Skip to content

Commit 9d84c4a

Browse files
Merge pull request #22065 from ChayimFriedman2/fix-clippy
internal: Fix 1.95.0 Clippy
2 parents b845801 + 48401bd commit 9d84c4a

28 files changed

Lines changed: 215 additions & 205 deletions

File tree

crates/hir-def/src/expr_store/lower.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,17 +2737,17 @@ impl<'db> ExprCollector<'db> {
27372737

27382738
for (rib_idx, rib) in self.label_ribs.iter().enumerate().rev() {
27392739
match &rib.kind {
2740-
RibKind::Normal(label_name, id, label_hygiene) => {
2741-
if *label_name == name && *label_hygiene == hygiene_id {
2742-
return if self.is_label_valid_from_rib(rib_idx) {
2743-
Ok(Some(*id))
2744-
} else {
2745-
Err(ExpressionStoreDiagnostics::UnreachableLabel {
2746-
name,
2747-
node: self.expander.in_file(AstPtr::new(&lifetime)),
2748-
})
2749-
};
2750-
}
2740+
RibKind::Normal(label_name, id, label_hygiene)
2741+
if *label_name == name && *label_hygiene == hygiene_id =>
2742+
{
2743+
return if self.is_label_valid_from_rib(rib_idx) {
2744+
Ok(Some(*id))
2745+
} else {
2746+
Err(ExpressionStoreDiagnostics::UnreachableLabel {
2747+
name,
2748+
node: self.expander.in_file(AstPtr::new(&lifetime)),
2749+
})
2750+
};
27512751
}
27522752
RibKind::MacroDef(macro_id) => {
27532753
if let Some((parent_ctx, label_macro_id)) = hygiene_info

crates/hir-def/src/item_scope.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -680,20 +680,19 @@ impl ItemScope {
680680
changed = true;
681681
}
682682
Entry::Occupied(mut entry)
683-
if !matches!(import, Some(ImportOrExternCrate::Glob(..))) =>
683+
if !matches!(import, Some(ImportOrExternCrate::Glob(..)))
684+
&& glob_imports.values.remove(&lookup) =>
684685
{
685-
if glob_imports.values.remove(&lookup) {
686-
cov_mark::hit!(import_shadowed);
687-
688-
let import = import.and_then(ImportOrExternCrate::import_or_glob);
689-
let prev = std::mem::replace(&mut fld.import, import);
690-
if let Some(import) = import {
691-
self.use_imports_values
692-
.insert(import, prev.map_or(ImportOrDef::Def(fld.def), Into::into));
693-
}
694-
entry.insert(fld);
695-
changed = true;
686+
cov_mark::hit!(import_shadowed);
687+
688+
let import = import.and_then(ImportOrExternCrate::import_or_glob);
689+
let prev = std::mem::replace(&mut fld.import, import);
690+
if let Some(import) = import {
691+
self.use_imports_values
692+
.insert(import, prev.map_or(ImportOrDef::Def(fld.def), Into::into));
696693
}
694+
entry.insert(fld);
695+
changed = true;
697696
}
698697
_ => {}
699698
}
@@ -720,20 +719,19 @@ impl ItemScope {
720719
changed = true;
721720
}
722721
Entry::Occupied(mut entry)
723-
if !matches!(import, Some(ImportOrExternCrate::Glob(..))) =>
722+
if !matches!(import, Some(ImportOrExternCrate::Glob(..)))
723+
&& glob_imports.macros.remove(&lookup) =>
724724
{
725-
if glob_imports.macros.remove(&lookup) {
726-
cov_mark::hit!(import_shadowed);
727-
let prev = std::mem::replace(&mut fld.import, import);
728-
if let Some(import) = import {
729-
self.use_imports_macros.insert(
730-
import,
731-
prev.map_or_else(|| ImportOrDef::Def(fld.def.into()), Into::into),
732-
);
733-
}
734-
entry.insert(fld);
735-
changed = true;
725+
cov_mark::hit!(import_shadowed);
726+
let prev = std::mem::replace(&mut fld.import, import);
727+
if let Some(import) = import {
728+
self.use_imports_macros.insert(
729+
import,
730+
prev.map_or_else(|| ImportOrDef::Def(fld.def.into()), Into::into),
731+
);
736732
}
733+
entry.insert(fld);
734+
changed = true;
737735
}
738736
_ => {}
739737
}

crates/hir-ty/src/infer.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,9 +1440,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
14401440
});
14411441

14421442
if placeholder_ids.len() == type_variables.len() {
1443-
for (placeholder_id, type_variable) in
1444-
placeholder_ids.into_iter().zip(type_variables.into_iter())
1445-
{
1443+
for (placeholder_id, type_variable) in placeholder_ids.into_iter().zip(type_variables) {
14461444
self.write_type_placeholder_ty(placeholder_id, type_variable);
14471445
}
14481446
}

crates/hir-ty/src/opaques.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ pub(crate) fn opaque_types_defined_by(
5555
.for_each(extend_with_taits);
5656
};
5757
let extend_with_atpit_from_container = |container| match container {
58-
ItemContainerId::ImplId(impl_id) => {
59-
if ImplSignature::of(db, impl_id).target_trait.is_some() {
60-
extend_with_atpit_from_assoc_items(&impl_id.impl_items(db).items);
61-
}
58+
ItemContainerId::ImplId(impl_id)
59+
if ImplSignature::of(db, impl_id).target_trait.is_some() =>
60+
{
61+
extend_with_atpit_from_assoc_items(&impl_id.impl_items(db).items);
6262
}
6363
ItemContainerId::TraitId(trait_id) => {
6464
extend_with_atpit_from_assoc_items(&trait_id.trait_items(db).items);
@@ -196,10 +196,10 @@ fn tait_defining_bodies(
196196
.collect()
197197
};
198198
match loc.container {
199-
ItemContainerId::ImplId(impl_id) => {
200-
if ImplSignature::of(db, impl_id).target_trait.is_some() {
201-
return from_assoc_items(&impl_id.impl_items(db).items);
202-
}
199+
ItemContainerId::ImplId(impl_id)
200+
if ImplSignature::of(db, impl_id).target_trait.is_some() =>
201+
{
202+
return from_assoc_items(&impl_id.impl_items(db).items);
203203
}
204204
ItemContainerId::TraitId(trait_id) => {
205205
return from_assoc_items(&trait_id.trait_items(db).items);

crates/hir/src/diagnostics.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -491,35 +491,35 @@ impl<'db> AnyDiagnostic<'db> {
491491
let file = record.file_id;
492492
let root = record.file_syntax(db);
493493
match record.value.to_node(&root) {
494-
Either::Left(ast::Expr::RecordExpr(record_expr)) => {
495-
if record_expr.record_expr_field_list().is_some() {
496-
let field_list_parent_path =
497-
record_expr.path().map(|path| AstPtr::new(&path));
498-
return Some(
499-
MissingFields {
500-
file,
501-
field_list_parent: AstPtr::new(&Either::Left(record_expr)),
502-
field_list_parent_path,
503-
missed_fields,
504-
}
505-
.into(),
506-
);
507-
}
494+
Either::Left(ast::Expr::RecordExpr(record_expr))
495+
if record_expr.record_expr_field_list().is_some() =>
496+
{
497+
let field_list_parent_path =
498+
record_expr.path().map(|path| AstPtr::new(&path));
499+
return Some(
500+
MissingFields {
501+
file,
502+
field_list_parent: AstPtr::new(&Either::Left(record_expr)),
503+
field_list_parent_path,
504+
missed_fields,
505+
}
506+
.into(),
507+
);
508508
}
509-
Either::Right(ast::Pat::RecordPat(record_pat)) => {
510-
if record_pat.record_pat_field_list().is_some() {
511-
let field_list_parent_path =
512-
record_pat.path().map(|path| AstPtr::new(&path));
513-
return Some(
514-
MissingFields {
515-
file,
516-
field_list_parent: AstPtr::new(&Either::Right(record_pat)),
517-
field_list_parent_path,
518-
missed_fields,
519-
}
520-
.into(),
521-
);
522-
}
509+
Either::Right(ast::Pat::RecordPat(record_pat))
510+
if record_pat.record_pat_field_list().is_some() =>
511+
{
512+
let field_list_parent_path =
513+
record_pat.path().map(|path| AstPtr::new(&path));
514+
return Some(
515+
MissingFields {
516+
file,
517+
field_list_parent: AstPtr::new(&Either::Right(record_pat)),
518+
field_list_parent_path,
519+
missed_fields,
520+
}
521+
.into(),
522+
);
523523
}
524524
_ => {}
525525
}

crates/ide-assists/src/handlers/extract_function.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,26 +1362,26 @@ fn node_to_insert_after(body: &FunctionBody, anchor: Anchor) -> Option<SyntaxNod
13621362
while let Some(next_ancestor) = ancestors.next() {
13631363
match next_ancestor.kind() {
13641364
SyntaxKind::SOURCE_FILE => break,
1365-
SyntaxKind::IMPL => {
1366-
if body.extracted_from_trait_impl() && matches!(anchor, Anchor::Method) {
1367-
let impl_node = find_non_trait_impl(&next_ancestor);
1368-
if let target_node @ Some(_) = impl_node.as_ref().and_then(last_impl_member) {
1369-
return target_node;
1370-
}
1365+
SyntaxKind::IMPL
1366+
if body.extracted_from_trait_impl() && matches!(anchor, Anchor::Method) =>
1367+
{
1368+
let impl_node = find_non_trait_impl(&next_ancestor);
1369+
if let target_node @ Some(_) = impl_node.as_ref().and_then(last_impl_member) {
1370+
return target_node;
13711371
}
13721372
}
13731373
SyntaxKind::ITEM_LIST if !matches!(anchor, Anchor::Freestanding) => continue,
1374-
SyntaxKind::ITEM_LIST => {
1375-
if ancestors.peek().map(SyntaxNode::kind) == Some(SyntaxKind::MODULE) {
1376-
break;
1377-
}
1374+
SyntaxKind::ITEM_LIST
1375+
if ancestors.peek().map(SyntaxNode::kind) == Some(SyntaxKind::MODULE) =>
1376+
{
1377+
break;
13781378
}
13791379
SyntaxKind::ASSOC_ITEM_LIST if !matches!(anchor, Anchor::Method) => continue,
13801380
SyntaxKind::ASSOC_ITEM_LIST if body.extracted_from_trait_impl() => continue,
1381-
SyntaxKind::ASSOC_ITEM_LIST => {
1382-
if ancestors.peek().map(SyntaxNode::kind) == Some(SyntaxKind::IMPL) {
1383-
break;
1384-
}
1381+
SyntaxKind::ASSOC_ITEM_LIST
1382+
if ancestors.peek().map(SyntaxNode::kind) == Some(SyntaxKind::IMPL) =>
1383+
{
1384+
break;
13851385
}
13861386
_ => (),
13871387
}
@@ -2128,19 +2128,19 @@ fn update_external_control_flow(handler: &FlowHandler<'_>, syntax: &SyntaxNode)
21282128
for event in syntax.preorder() {
21292129
match event {
21302130
WalkEvent::Enter(e) => match e.kind() {
2131-
SyntaxKind::LOOP_EXPR | SyntaxKind::WHILE_EXPR | SyntaxKind::FOR_EXPR => {
2132-
if nested_loop.is_none() {
2133-
nested_loop = Some(e.clone());
2134-
}
2131+
SyntaxKind::LOOP_EXPR | SyntaxKind::WHILE_EXPR | SyntaxKind::FOR_EXPR
2132+
if nested_loop.is_none() =>
2133+
{
2134+
nested_loop = Some(e.clone());
21352135
}
21362136
SyntaxKind::FN
21372137
| SyntaxKind::CONST
21382138
| SyntaxKind::STATIC
21392139
| SyntaxKind::IMPL
2140-
| SyntaxKind::MODULE => {
2141-
if nested_scope.is_none() {
2142-
nested_scope = Some(e.clone());
2143-
}
2140+
| SyntaxKind::MODULE
2141+
if nested_scope.is_none() =>
2142+
{
2143+
nested_scope = Some(e.clone());
21442144
}
21452145
_ => {}
21462146
},

crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ fn extract_generic_params(
215215
) -> Option<ast::GenericParamList> {
216216
let mut generics = known_generics.generic_params().map(|param| (param, false)).collect_vec();
217217

218+
#[expect(clippy::unnecessary_fold, reason = "this function has side effects")]
218219
let tagged_one = match field_list {
219220
Either::Left(field_list) => field_list
220221
.fields()
@@ -248,6 +249,10 @@ fn tag_generics_in_variant(ty: &ast::Type, generics: &mut [(ast::GenericParam, b
248249
}
249250
}
250251
param if matches!(token.kind(), T![ident]) => {
252+
#[expect(
253+
clippy::collapsible_match,
254+
reason = "it won't compile since in the guard, `param` is immutable"
255+
)]
251256
if match param {
252257
ast::GenericParam::ConstParam(konst) => konst
253258
.name()

crates/ide-assists/src/handlers/generate_function.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,10 +1166,10 @@ fn next_space_for_fn_after_call_site(expr: ast::CallableExpr) -> Option<Generate
11661166
SyntaxKind::SOURCE_FILE => {
11671167
break;
11681168
}
1169-
SyntaxKind::ITEM_LIST => {
1170-
if ancestors.peek().map(|a| a.kind()) == Some(SyntaxKind::MODULE) {
1171-
break;
1172-
}
1169+
SyntaxKind::ITEM_LIST
1170+
if ancestors.peek().map(|a| a.kind()) == Some(SyntaxKind::MODULE) =>
1171+
{
1172+
break;
11731173
}
11741174
_ => {}
11751175
}

crates/ide-assists/src/utils/gen_trait_fn_body.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn gen_clone_impl(make: &SyntaxFactory, adt: &ast::Adt) -> Option<ast::BlockExpr
9595
let f_path = make.expr_path(make.ident_path(&field_name));
9696
fields.push(gen_clone_call(f_path));
9797
}
98-
let pat = make.tuple_struct_pat(variant_name.clone(), pats.into_iter());
98+
let pat = make.tuple_struct_pat(variant_name.clone(), pats);
9999
let struct_name = make.expr_path(variant_name);
100100
let tuple_expr = make.expr_call(struct_name, make.arg_list(fields)).into();
101101
arms.push(make.match_arm(pat.into(), None, tuple_expr));
@@ -236,7 +236,7 @@ fn gen_debug_impl(make: &SyntaxFactory, adt: &ast::Adt) -> Option<ast::BlockExpr
236236
let expr = make.expr_method_call(expr, method, make.arg_list([])).into();
237237

238238
// => MyStruct (fields..) => f.debug_tuple("MyStruct")...finish(),
239-
let pat = make.tuple_struct_pat(variant_name.clone(), pats.into_iter());
239+
let pat = make.tuple_struct_pat(variant_name.clone(), pats);
240240
arms.push(make.match_arm(pat.into(), None, expr));
241241
}
242242
None => {

crates/ide-completion/src/completions/expr.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,12 @@ pub(crate) fn complete_expr_path(
317317
}
318318
// synthetic names currently leak out as we lack synthetic hygiene, so filter them
319319
// out here
320-
ScopeDef::Local(_) => {
320+
ScopeDef::Local(_) =>
321+
{
322+
#[expect(
323+
clippy::collapsible_match,
324+
reason = "this changes meaning, causing the next arm to be selected"
325+
)]
321326
if !name.as_str().starts_with('<') {
322327
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases)
323328
}

0 commit comments

Comments
 (0)