Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #22065 from ChayimFriedman2/fix-clippy
internal: Fix 1.95.0 Clippy
Chayim Refael Friedman 5 weeks ago
parent b845801 · parent 48401bd · commit 9d84c4a
-rw-r--r--crates/hir-def/src/expr_store/lower.rs22
-rw-r--r--crates/hir-def/src/item_scope.rs46
-rw-r--r--crates/hir-ty/src/infer.rs4
-rw-r--r--crates/hir-ty/src/opaques.rs16
-rw-r--r--crates/hir/src/diagnostics.rs56
-rw-r--r--crates/ide-assists/src/handlers/extract_function.rs44
-rw-r--r--crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs5
-rw-r--r--crates/ide-assists/src/handlers/generate_function.rs8
-rw-r--r--crates/ide-assists/src/utils/gen_trait_fn_body.rs4
-rw-r--r--crates/ide-completion/src/completions/expr.rs7
-rw-r--r--crates/ide-completion/src/completions/type.rs42
-rw-r--r--crates/ide-completion/src/context/analysis.rs14
-rw-r--r--crates/ide-db/src/search.rs23
-rw-r--r--crates/ide-db/src/syntax_helpers/format_string_exprs.rs2
-rw-r--r--crates/ide-db/src/syntax_helpers/node_ext.rs7
-rw-r--r--crates/ide/src/folding_ranges.rs2
-rw-r--r--crates/ide/src/inlay_hints/lifetime.rs26
-rw-r--r--crates/ide/src/runnables.rs8
-rw-r--r--crates/ide/src/syntax_highlighting/highlight.rs12
-rw-r--r--crates/load-cargo/src/lib.rs10
-rw-r--r--crates/parser/src/grammar.rs19
-rw-r--r--crates/proc-macro-api/src/legacy_protocol/msg/flat.rs4
-rw-r--r--crates/project-model/src/env.rs2
-rw-r--r--crates/rust-analyzer/src/main_loop.rs11
-rw-r--r--crates/syntax/src/ast/edit_in_place.rs9
-rw-r--r--crates/syntax/src/syntax_editor.rs4
-rw-r--r--crates/syntax/src/syntax_editor/edits.rs9
-rw-r--r--xtask/src/tidy.rs4
28 files changed, 215 insertions, 205 deletions
diff --git a/crates/hir-def/src/expr_store/lower.rs b/crates/hir-def/src/expr_store/lower.rs
index 8a23ea69b8..2a1ed0afa9 100644
--- a/crates/hir-def/src/expr_store/lower.rs
+++ b/crates/hir-def/src/expr_store/lower.rs
@@ -2737,17 +2737,17 @@ impl<'db> ExprCollector<'db> {
for (rib_idx, rib) in self.label_ribs.iter().enumerate().rev() {
match &rib.kind {
- RibKind::Normal(label_name, id, label_hygiene) => {
- if *label_name == name && *label_hygiene == hygiene_id {
- return if self.is_label_valid_from_rib(rib_idx) {
- Ok(Some(*id))
- } else {
- Err(ExpressionStoreDiagnostics::UnreachableLabel {
- name,
- node: self.expander.in_file(AstPtr::new(&lifetime)),
- })
- };
- }
+ RibKind::Normal(label_name, id, label_hygiene)
+ if *label_name == name && *label_hygiene == hygiene_id =>
+ {
+ return if self.is_label_valid_from_rib(rib_idx) {
+ Ok(Some(*id))
+ } else {
+ Err(ExpressionStoreDiagnostics::UnreachableLabel {
+ name,
+ node: self.expander.in_file(AstPtr::new(&lifetime)),
+ })
+ };
}
RibKind::MacroDef(macro_id) => {
if let Some((parent_ctx, label_macro_id)) = hygiene_info
diff --git a/crates/hir-def/src/item_scope.rs b/crates/hir-def/src/item_scope.rs
index b11a8bcd90..fe7d180685 100644
--- a/crates/hir-def/src/item_scope.rs
+++ b/crates/hir-def/src/item_scope.rs
@@ -680,20 +680,19 @@ impl ItemScope {
changed = true;
}
Entry::Occupied(mut entry)
- if !matches!(import, Some(ImportOrExternCrate::Glob(..))) =>
+ if !matches!(import, Some(ImportOrExternCrate::Glob(..)))
+ && glob_imports.values.remove(&lookup) =>
{
- if glob_imports.values.remove(&lookup) {
- cov_mark::hit!(import_shadowed);
-
- let import = import.and_then(ImportOrExternCrate::import_or_glob);
- let prev = std::mem::replace(&mut fld.import, import);
- if let Some(import) = import {
- self.use_imports_values
- .insert(import, prev.map_or(ImportOrDef::Def(fld.def), Into::into));
- }
- entry.insert(fld);
- changed = true;
+ cov_mark::hit!(import_shadowed);
+
+ let import = import.and_then(ImportOrExternCrate::import_or_glob);
+ let prev = std::mem::replace(&mut fld.import, import);
+ if let Some(import) = import {
+ self.use_imports_values
+ .insert(import, prev.map_or(ImportOrDef::Def(fld.def), Into::into));
}
+ entry.insert(fld);
+ changed = true;
}
_ => {}
}
@@ -720,20 +719,19 @@ impl ItemScope {
changed = true;
}
Entry::Occupied(mut entry)
- if !matches!(import, Some(ImportOrExternCrate::Glob(..))) =>
+ if !matches!(import, Some(ImportOrExternCrate::Glob(..)))
+ && glob_imports.macros.remove(&lookup) =>
{
- if glob_imports.macros.remove(&lookup) {
- cov_mark::hit!(import_shadowed);
- let prev = std::mem::replace(&mut fld.import, import);
- if let Some(import) = import {
- self.use_imports_macros.insert(
- import,
- prev.map_or_else(|| ImportOrDef::Def(fld.def.into()), Into::into),
- );
- }
- entry.insert(fld);
- changed = true;
+ cov_mark::hit!(import_shadowed);
+ let prev = std::mem::replace(&mut fld.import, import);
+ if let Some(import) = import {
+ self.use_imports_macros.insert(
+ import,
+ prev.map_or_else(|| ImportOrDef::Def(fld.def.into()), Into::into),
+ );
}
+ entry.insert(fld);
+ changed = true;
}
_ => {}
}
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index 70083dbe3e..d16bef1c94 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -1440,9 +1440,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
});
if placeholder_ids.len() == type_variables.len() {
- for (placeholder_id, type_variable) in
- placeholder_ids.into_iter().zip(type_variables.into_iter())
- {
+ for (placeholder_id, type_variable) in placeholder_ids.into_iter().zip(type_variables) {
self.write_type_placeholder_ty(placeholder_id, type_variable);
}
}
diff --git a/crates/hir-ty/src/opaques.rs b/crates/hir-ty/src/opaques.rs
index ce93a33422..2e85beea91 100644
--- a/crates/hir-ty/src/opaques.rs
+++ b/crates/hir-ty/src/opaques.rs
@@ -55,10 +55,10 @@ pub(crate) fn opaque_types_defined_by(
.for_each(extend_with_taits);
};
let extend_with_atpit_from_container = |container| match container {
- ItemContainerId::ImplId(impl_id) => {
- if ImplSignature::of(db, impl_id).target_trait.is_some() {
- extend_with_atpit_from_assoc_items(&impl_id.impl_items(db).items);
- }
+ ItemContainerId::ImplId(impl_id)
+ if ImplSignature::of(db, impl_id).target_trait.is_some() =>
+ {
+ extend_with_atpit_from_assoc_items(&impl_id.impl_items(db).items);
}
ItemContainerId::TraitId(trait_id) => {
extend_with_atpit_from_assoc_items(&trait_id.trait_items(db).items);
@@ -196,10 +196,10 @@ fn tait_defining_bodies(
.collect()
};
match loc.container {
- ItemContainerId::ImplId(impl_id) => {
- if ImplSignature::of(db, impl_id).target_trait.is_some() {
- return from_assoc_items(&impl_id.impl_items(db).items);
- }
+ ItemContainerId::ImplId(impl_id)
+ if ImplSignature::of(db, impl_id).target_trait.is_some() =>
+ {
+ return from_assoc_items(&impl_id.impl_items(db).items);
}
ItemContainerId::TraitId(trait_id) => {
return from_assoc_items(&trait_id.trait_items(db).items);
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs
index 555270bad8..6cfb79d5a1 100644
--- a/crates/hir/src/diagnostics.rs
+++ b/crates/hir/src/diagnostics.rs
@@ -491,35 +491,35 @@ impl<'db> AnyDiagnostic<'db> {
let file = record.file_id;
let root = record.file_syntax(db);
match record.value.to_node(&root) {
- Either::Left(ast::Expr::RecordExpr(record_expr)) => {
- if record_expr.record_expr_field_list().is_some() {
- let field_list_parent_path =
- record_expr.path().map(|path| AstPtr::new(&path));
- return Some(
- MissingFields {
- file,
- field_list_parent: AstPtr::new(&Either::Left(record_expr)),
- field_list_parent_path,
- missed_fields,
- }
- .into(),
- );
- }
+ Either::Left(ast::Expr::RecordExpr(record_expr))
+ if record_expr.record_expr_field_list().is_some() =>
+ {
+ let field_list_parent_path =
+ record_expr.path().map(|path| AstPtr::new(&path));
+ return Some(
+ MissingFields {
+ file,
+ field_list_parent: AstPtr::new(&Either::Left(record_expr)),
+ field_list_parent_path,
+ missed_fields,
+ }
+ .into(),
+ );
}
- Either::Right(ast::Pat::RecordPat(record_pat)) => {
- if record_pat.record_pat_field_list().is_some() {
- let field_list_parent_path =
- record_pat.path().map(|path| AstPtr::new(&path));
- return Some(
- MissingFields {
- file,
- field_list_parent: AstPtr::new(&Either::Right(record_pat)),
- field_list_parent_path,
- missed_fields,
- }
- .into(),
- );
- }
+ Either::Right(ast::Pat::RecordPat(record_pat))
+ if record_pat.record_pat_field_list().is_some() =>
+ {
+ let field_list_parent_path =
+ record_pat.path().map(|path| AstPtr::new(&path));
+ return Some(
+ MissingFields {
+ file,
+ field_list_parent: AstPtr::new(&Either::Right(record_pat)),
+ field_list_parent_path,
+ missed_fields,
+ }
+ .into(),
+ );
}
_ => {}
}
diff --git a/crates/ide-assists/src/handlers/extract_function.rs b/crates/ide-assists/src/handlers/extract_function.rs
index 4865aa7173..4219e6845f 100644
--- a/crates/ide-assists/src/handlers/extract_function.rs
+++ b/crates/ide-assists/src/handlers/extract_function.rs
@@ -1362,26 +1362,26 @@ fn node_to_insert_after(body: &FunctionBody, anchor: Anchor) -> Option<SyntaxNod
while let Some(next_ancestor) = ancestors.next() {
match next_ancestor.kind() {
SyntaxKind::SOURCE_FILE => break,
- SyntaxKind::IMPL => {
- if body.extracted_from_trait_impl() && matches!(anchor, Anchor::Method) {
- let impl_node = find_non_trait_impl(&next_ancestor);
- if let target_node @ Some(_) = impl_node.as_ref().and_then(last_impl_member) {
- return target_node;
- }
+ SyntaxKind::IMPL
+ if body.extracted_from_trait_impl() && matches!(anchor, Anchor::Method) =>
+ {
+ let impl_node = find_non_trait_impl(&next_ancestor);
+ if let target_node @ Some(_) = impl_node.as_ref().and_then(last_impl_member) {
+ return target_node;
}
}
SyntaxKind::ITEM_LIST if !matches!(anchor, Anchor::Freestanding) => continue,
- SyntaxKind::ITEM_LIST => {
- if ancestors.peek().map(SyntaxNode::kind) == Some(SyntaxKind::MODULE) {
- break;
- }
+ SyntaxKind::ITEM_LIST
+ if ancestors.peek().map(SyntaxNode::kind) == Some(SyntaxKind::MODULE) =>
+ {
+ break;
}
SyntaxKind::ASSOC_ITEM_LIST if !matches!(anchor, Anchor::Method) => continue,
SyntaxKind::ASSOC_ITEM_LIST if body.extracted_from_trait_impl() => continue,
- SyntaxKind::ASSOC_ITEM_LIST => {
- if ancestors.peek().map(SyntaxNode::kind) == Some(SyntaxKind::IMPL) {
- break;
- }
+ SyntaxKind::ASSOC_ITEM_LIST
+ if ancestors.peek().map(SyntaxNode::kind) == Some(SyntaxKind::IMPL) =>
+ {
+ break;
}
_ => (),
}
@@ -2128,19 +2128,19 @@ fn update_external_control_flow(handler: &FlowHandler<'_>, syntax: &SyntaxNode)
for event in syntax.preorder() {
match event {
WalkEvent::Enter(e) => match e.kind() {
- SyntaxKind::LOOP_EXPR | SyntaxKind::WHILE_EXPR | SyntaxKind::FOR_EXPR => {
- if nested_loop.is_none() {
- nested_loop = Some(e.clone());
- }
+ SyntaxKind::LOOP_EXPR | SyntaxKind::WHILE_EXPR | SyntaxKind::FOR_EXPR
+ if nested_loop.is_none() =>
+ {
+ nested_loop = Some(e.clone());
}
SyntaxKind::FN
| SyntaxKind::CONST
| SyntaxKind::STATIC
| SyntaxKind::IMPL
- | SyntaxKind::MODULE => {
- if nested_scope.is_none() {
- nested_scope = Some(e.clone());
- }
+ | SyntaxKind::MODULE
+ if nested_scope.is_none() =>
+ {
+ nested_scope = Some(e.clone());
}
_ => {}
},
diff --git a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
index 3272fa739f..21013e2e61 100644
--- a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -215,6 +215,7 @@ fn extract_generic_params(
) -> Option<ast::GenericParamList> {
let mut generics = known_generics.generic_params().map(|param| (param, false)).collect_vec();
+ #[expect(clippy::unnecessary_fold, reason = "this function has side effects")]
let tagged_one = match field_list {
Either::Left(field_list) => field_list
.fields()
@@ -248,6 +249,10 @@ fn tag_generics_in_variant(ty: &ast::Type, generics: &mut [(ast::GenericParam, b
}
}
param if matches!(token.kind(), T![ident]) => {
+ #[expect(
+ clippy::collapsible_match,
+ reason = "it won't compile since in the guard, `param` is immutable"
+ )]
if match param {
ast::GenericParam::ConstParam(konst) => konst
.name()
diff --git a/crates/ide-assists/src/handlers/generate_function.rs b/crates/ide-assists/src/handlers/generate_function.rs
index fbf6241e43..6ef492619b 100644
--- a/crates/ide-assists/src/handlers/generate_function.rs
+++ b/crates/ide-assists/src/handlers/generate_function.rs
@@ -1166,10 +1166,10 @@ fn next_space_for_fn_after_call_site(expr: ast::CallableExpr) -> Option<Generate
SyntaxKind::SOURCE_FILE => {
break;
}
- SyntaxKind::ITEM_LIST => {
- if ancestors.peek().map(|a| a.kind()) == Some(SyntaxKind::MODULE) {
- break;
- }
+ SyntaxKind::ITEM_LIST
+ if ancestors.peek().map(|a| a.kind()) == Some(SyntaxKind::MODULE) =>
+ {
+ break;
}
_ => {}
}
diff --git a/crates/ide-assists/src/utils/gen_trait_fn_body.rs b/crates/ide-assists/src/utils/gen_trait_fn_body.rs
index b0d88737fe..c0ddcb950c 100644
--- a/crates/ide-assists/src/utils/gen_trait_fn_body.rs
+++ b/crates/ide-assists/src/utils/gen_trait_fn_body.rs
@@ -95,7 +95,7 @@ fn gen_clone_impl(make: &SyntaxFactory, adt: &ast::Adt) -> Option<ast::BlockExpr
let f_path = make.expr_path(make.ident_path(&field_name));
fields.push(gen_clone_call(f_path));
}
- let pat = make.tuple_struct_pat(variant_name.clone(), pats.into_iter());
+ let pat = make.tuple_struct_pat(variant_name.clone(), pats);
let struct_name = make.expr_path(variant_name);
let tuple_expr = make.expr_call(struct_name, make.arg_list(fields)).into();
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
let expr = make.expr_method_call(expr, method, make.arg_list([])).into();
// => MyStruct (fields..) => f.debug_tuple("MyStruct")...finish(),
- let pat = make.tuple_struct_pat(variant_name.clone(), pats.into_iter());
+ let pat = make.tuple_struct_pat(variant_name.clone(), pats);
arms.push(make.match_arm(pat.into(), None, expr));
}
None => {
diff --git a/crates/ide-completion/src/completions/expr.rs b/crates/ide-completion/src/completions/expr.rs
index 99ca55bdaf..c15c67173e 100644
--- a/crates/ide-completion/src/completions/expr.rs
+++ b/crates/ide-completion/src/completions/expr.rs
@@ -317,7 +317,12 @@ pub(crate) fn complete_expr_path(
}
// synthetic names currently leak out as we lack synthetic hygiene, so filter them
// out here
- ScopeDef::Local(_) => {
+ ScopeDef::Local(_) =>
+ {
+ #[expect(
+ clippy::collapsible_match,
+ reason = "this changes meaning, causing the next arm to be selected"
+ )]
if !name.as_str().starts_with('<') {
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases)
}
diff --git a/crates/ide-completion/src/completions/type.rs b/crates/ide-completion/src/completions/type.rs
index e2125a9678..20bbf0dd8b 100644
--- a/crates/ide-completion/src/completions/type.rs
+++ b/crates/ide-completion/src/completions/type.rs
@@ -162,29 +162,27 @@ pub(crate) fn complete_type_path(
}
TypeLocation::GenericArg {
args: Some(arg_list), of_trait: Some(trait_), ..
- } => {
- if arg_list.syntax().ancestors().find_map(ast::TypeBound::cast).is_some() {
- let arg_idx = arg_list
- .generic_args()
- .filter(|arg| {
- arg.syntax().text_range().end()
- < ctx.original_token.text_range().start()
- })
- .count();
-
- let n_required_params = trait_.type_or_const_param_count(ctx.sema.db, true);
- if arg_idx >= n_required_params {
- trait_.items_with_supertraits(ctx.sema.db).into_iter().for_each(|it| {
- if let hir::AssocItem::TypeAlias(alias) = it {
- cov_mark::hit!(complete_assoc_type_in_generics_list);
- acc.add_type_alias_with_eq(ctx, alias);
- }
- });
-
- let n_params = trait_.type_or_const_param_count(ctx.sema.db, false);
- if arg_idx >= n_params {
- return; // only show assoc types
+ } if arg_list.syntax().ancestors().find_map(ast::TypeBound::cast).is_some() => {
+ let arg_idx = arg_list
+ .generic_args()
+ .filter(|arg| {
+ arg.syntax().text_range().end()
+ < ctx.original_token.text_range().start()
+ })
+ .count();
+
+ let n_required_params = trait_.type_or_const_param_count(ctx.sema.db, true);
+ if arg_idx >= n_required_params {
+ trait_.items_with_supertraits(ctx.sema.db).into_iter().for_each(|it| {
+ if let hir::AssocItem::TypeAlias(alias) = it {
+ cov_mark::hit!(complete_assoc_type_in_generics_list);
+ acc.add_type_alias_with_eq(ctx, alias);
}
+ });
+
+ let n_params = trait_.type_or_const_param_count(ctx.sema.db, false);
+ if arg_idx >= n_params {
+ return; // only show assoc types
}
}
}
diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs
index 60f5dabefc..58c0f683a3 100644
--- a/crates/ide-completion/src/context/analysis.rs
+++ b/crates/ide-completion/src/context/analysis.rs
@@ -1183,18 +1183,16 @@ fn classify_name_ref<'db>(
let arg_name = arg_name.text();
for item in trait_.items_with_supertraits(sema.db) {
match item {
- hir::AssocItem::TypeAlias(assoc_ty) => {
- if assoc_ty.name(sema.db).as_str() == arg_name {
+ hir::AssocItem::TypeAlias(assoc_ty)
+ if assoc_ty.name(sema.db).as_str() == arg_name => {
override_location = Some(TypeLocation::AssocTypeEq);
return None;
- }
- },
- hir::AssocItem::Const(const_) => {
- if const_.name(sema.db)?.as_str() == arg_name {
+ },
+ hir::AssocItem::Const(const_)
+ if const_.name(sema.db)?.as_str() == arg_name => {
override_location = Some(TypeLocation::AssocConstEq);
return None;
- }
- },
+ },
_ => (),
}
}
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs
index 69459a4b72..8b63fb9bea 100644
--- a/crates/ide-db/src/search.rs
+++ b/crates/ide-db/src/search.rs
@@ -1241,18 +1241,17 @@ impl<'a> FindUsages<'a> {
};
sink(file_id, reference)
}
- Some(NameRefClass::Definition(def, _)) if self.include_self_kw_refs.is_some() => {
- if self.include_self_kw_refs == def_to_ty(self.sema, &def) {
- let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax());
- let reference = FileReference {
- range,
- name: FileReferenceNode::NameRef(name_ref.clone()),
- category: ReferenceCategory::new(self.sema, &def, name_ref),
- };
- sink(file_id, reference)
- } else {
- false
- }
+ Some(NameRefClass::Definition(def, _))
+ if self.include_self_kw_refs.is_some()
+ && self.include_self_kw_refs == def_to_ty(self.sema, &def) =>
+ {
+ let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax());
+ let reference = FileReference {
+ range,
+ name: FileReferenceNode::NameRef(name_ref.clone()),
+ category: ReferenceCategory::new(self.sema, &def, name_ref),
+ };
+ sink(file_id, reference)
}
Some(NameRefClass::FieldShorthand {
local_ref: local,
diff --git a/crates/ide-db/src/syntax_helpers/format_string_exprs.rs b/crates/ide-db/src/syntax_helpers/format_string_exprs.rs
index 8f25833fff..6cc3334196 100644
--- a/crates/ide-db/src/syntax_helpers/format_string_exprs.rs
+++ b/crates/ide-db/src/syntax_helpers/format_string_exprs.rs
@@ -125,7 +125,7 @@ pub fn parse_format_exprs(input: &str) -> Result<(String, Vec<Arg>), ()> {
// if the expression consists of a single number, like "0" or "12", it can refer to
// format args in the order they are specified.
// see: https://doc.rust-lang.org/std/fmt/#positional-parameters
- if trimmed.chars().fold(true, |only_num, c| c.is_ascii_digit() && only_num) {
+ if trimmed.chars().all(|c| c.is_ascii_digit()) {
output.push_str(trimmed);
} else if matches!(state, State::Expr) {
extracted_expressions.push(Arg::Expr(trimmed.into()));
diff --git a/crates/ide-db/src/syntax_helpers/node_ext.rs b/crates/ide-db/src/syntax_helpers/node_ext.rs
index e30b21c139..11ba815dab 100644
--- a/crates/ide-db/src/syntax_helpers/node_ext.rs
+++ b/crates/ide-db/src/syntax_helpers/node_ext.rs
@@ -216,7 +216,12 @@ pub fn walk_ty(ty: &ast::Type, cb: &mut dyn FnMut(ast::Type) -> bool) {
preorder.skip_subtree();
cb(ty);
}
- Some(ty) => {
+ Some(ty) =>
+ {
+ #[expect(
+ clippy::collapsible_match,
+ reason = "it won't compile due to exhaustiveness"
+ )]
if cb(ty) {
preorder.skip_subtree();
}
diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs
index 375e42cc83..965190b27d 100644
--- a/crates/ide/src/folding_ranges.rs
+++ b/crates/ide/src/folding_ranges.rs
@@ -487,7 +487,7 @@ mod tests {
"The amount of folds is different than the expected amount"
);
- for (fold, (range, attr, collapsed_text)) in folds.iter().zip(ranges.into_iter()) {
+ for (fold, (range, attr, collapsed_text)) in folds.iter().zip(ranges) {
assert_eq!(fold.range.start(), range.start(), "mismatched start of folding ranges");
assert_eq!(fold.range.end(), range.end(), "mismatched end of folding ranges");
diff --git a/crates/ide/src/inlay_hints/lifetime.rs b/crates/ide/src/inlay_hints/lifetime.rs
index 4982b60f1d..b12b296d34 100644
--- a/crates/ide/src/inlay_hints/lifetime.rs
+++ b/crates/ide/src/inlay_hints/lifetime.rs
@@ -240,17 +240,14 @@ fn hints_(
is_trivial = false;
true
}
- ast::Type::PathType(t) => {
+ ast::Type::PathType(t)
if t.path()
.and_then(|it| it.segment())
.and_then(|it| it.parenthesized_arg_list())
- .is_some()
- {
- is_trivial = false;
- true
- } else {
- false
- }
+ .is_some() =>
+ {
+ is_trivial = false;
+ true
}
_ => false,
})
@@ -339,17 +336,14 @@ fn hints_(
is_trivial = false;
true
}
- ast::Type::PathType(t) => {
+ ast::Type::PathType(t)
if t.path()
.and_then(|it| it.segment())
.and_then(|it| it.parenthesized_arg_list())
- .is_some()
- {
- is_trivial = false;
- true
- } else {
- false
- }
+ .is_some() =>
+ {
+ is_trivial = false;
+ true
}
_ => false,
})
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index 3b472390d2..60750608a5 100644
--- a/crates/ide/src/runnables.rs
+++ b/crates/ide/src/runnables.rs
@@ -606,14 +606,14 @@ fn has_test_function_or_multiple_test_submodules(
return true;
}
}
- hir::ModuleDef::Module(submodule) => {
+ hir::ModuleDef::Module(submodule)
if has_test_function_or_multiple_test_submodules(
sema,
&submodule,
consider_exported_main,
- ) {
- number_of_test_submodules += 1;
- }
+ ) =>
+ {
+ number_of_test_submodules += 1;
}
_ => (),
}
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs
index 0e101ab235..6823736d12 100644
--- a/crates/ide/src/syntax_highlighting/highlight.rs
+++ b/crates/ide/src/syntax_highlighting/highlight.rs
@@ -307,12 +307,12 @@ fn highlight_name_ref(
h |= HlMod::Consuming;
}
// highlight unsafe traits as unsafe only in their implementations
- Definition::Trait(trait_) if trait_.is_unsafe(db) => {
- if ast::Impl::for_trait_name_ref(&name_ref)
- .is_some_and(|impl_| impl_.unsafe_token().is_some())
- {
- h |= HlMod::Unsafe;
- }
+ Definition::Trait(trait_)
+ if trait_.is_unsafe(db)
+ && ast::Impl::for_trait_name_ref(&name_ref)
+ .is_some_and(|impl_| impl_.unsafe_token().is_some()) =>
+ {
+ h |= HlMod::Unsafe;
}
Definition::Function(_) => {
let is_unsafe = name_ref
diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs
index 68bf78e037..839df18159 100644
--- a/crates/load-cargo/src/lib.rs
+++ b/crates/load-cargo/src/lib.rs
@@ -884,7 +884,7 @@ mod tests {
let fsc = builder.build();
let src = SourceRootConfig { fsc, local_filesets: vec![0, 1, 2, 3] };
let mut vc = src.source_root_parent_map().into_iter().collect::<Vec<_>>();
- vc.sort_by(|x, y| x.0.0.cmp(&y.0.0));
+ vc.sort_by_key(|x| x.0.0);
assert_eq!(vc, vec![(SourceRootId(2), SourceRootId(1)), (SourceRootId(3), SourceRootId(1))])
}
@@ -899,7 +899,7 @@ mod tests {
let fsc = builder.build();
let src = SourceRootConfig { fsc, local_filesets: vec![0, 1, 3] };
let mut vc = src.source_root_parent_map().into_iter().collect::<Vec<_>>();
- vc.sort_by(|x, y| x.0.0.cmp(&y.0.0));
+ vc.sort_by_key(|x| x.0.0);
assert_eq!(vc, vec![(SourceRootId(3), SourceRootId(1)),])
}
@@ -914,7 +914,7 @@ mod tests {
let fsc = builder.build();
let src = SourceRootConfig { fsc, local_filesets: vec![0, 1, 3] };
let mut vc = src.source_root_parent_map().into_iter().collect::<Vec<_>>();
- vc.sort_by(|x, y| x.0.0.cmp(&y.0.0));
+ vc.sort_by_key(|x| x.0.0);
assert_eq!(vc, vec![(SourceRootId(3), SourceRootId(1)),])
}
@@ -930,7 +930,7 @@ mod tests {
let fsc = builder.build();
let src = SourceRootConfig { fsc, local_filesets: vec![0, 1] };
let mut vc = src.source_root_parent_map().into_iter().collect::<Vec<_>>();
- vc.sort_by(|x, y| x.0.0.cmp(&y.0.0));
+ vc.sort_by_key(|x| x.0.0);
assert_eq!(vc, vec![(SourceRootId(1), SourceRootId(0)),])
}
@@ -946,7 +946,7 @@ mod tests {
let fsc = builder.build();
let src = SourceRootConfig { fsc, local_filesets: vec![0, 1] };
let mut vc = src.source_root_parent_map().into_iter().collect::<Vec<_>>();
- vc.sort_by(|x, y| x.0.0.cmp(&y.0.0));
+ vc.sort_by_key(|x| x.0.0);
assert_eq!(vc, vec![(SourceRootId(1), SourceRootId(0)),])
}
diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs
index e8a9ddde69..0623e7ea19 100644
--- a/crates/parser/src/grammar.rs
+++ b/crates/parser/src/grammar.rs
@@ -250,7 +250,8 @@ fn opt_visibility_inner(p: &mut Parser<'_>, in_tuple_field: bool) -> bool {
// test pub_parens_typepath
// struct B(pub (super::A));
// struct B(pub (crate::A,));
- T![crate] | T![self] | T![super] | T![ident] | T![')'] if p.nth(2) != T![:] => {
+ T![crate] | T![self] | T![super] | T![ident] | T![')']
+ if p.nth(2) != T![:]
// If we are in a tuple struct, then the parens following `pub`
// might be an tuple field, not part of the visibility. So in that
// case we don't want to consume an identifier.
@@ -259,14 +260,14 @@ fn opt_visibility_inner(p: &mut Parser<'_>, in_tuple_field: bool) -> bool {
// struct MyStruct(pub (u32, u32));
// struct MyStruct(pub (u32));
// struct MyStruct(pub ());
- if !(in_tuple_field && matches!(p.nth(1), T![ident] | T![')'])) {
- let m = p.start();
- p.bump(T!['(']);
- paths::vis_path(p);
- p.expect(T![')']);
- m.complete(p, VISIBILITY_INNER);
- return true;
- }
+ && !(in_tuple_field && matches!(p.nth(1), T![ident] | T![')'])) =>
+ {
+ let m = p.start();
+ p.bump(T!['(']);
+ paths::vis_path(p);
+ p.expect(T![')']);
+ m.complete(p, VISIBILITY_INNER);
+ return true;
}
// test crate_visibility_in
// pub(in super::A) struct S;
diff --git a/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs b/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs
index cd8944aa61..248de70f0e 100644
--- a/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs
+++ b/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs
@@ -495,6 +495,10 @@ impl<'a, T: SpanTransformer<Span = span::Span>> Writer<'a, '_, T, tt::iter::TtIt
}
}
+ #[expect(
+ clippy::explicit_counter_loop,
+ reason = "it looks better the current way since we use `first_tt` before the loop"
+ )]
fn subtree(&mut self, idx: usize, n_tt: usize, subtree: tt::iter::TtIter<'a>) {
let mut first_tt = self.token_tree.len();
self.token_tree.resize(first_tt + n_tt, !0);
diff --git a/crates/project-model/src/env.rs b/crates/project-model/src/env.rs
index ab45917a56..37cfcd5545 100644
--- a/crates/project-model/src/env.rs
+++ b/crates/project-model/src/env.rs
@@ -160,7 +160,7 @@ env.RA_TEST_NOT_AN_OBJECT = "value"
("RA_TEST_UNSET", None),
]
.iter()
- .map(|(k, v)| (k.to_string(), v.map(ToString::to_string)))
+ .map(|(k, v)| (k.to_string(), v.map(str::to_owned)))
.collect();
let env = cargo_config_env(&Some(config), &extra_env);
assert_eq!(env.get("RA_TEST_WORKSPACE_DIR").as_deref(), Some(cwd.join("").as_str()));
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index a8c3d062d0..f5b3658ea9 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -144,12 +144,11 @@ impl fmt::Debug for Event {
};
match self {
- Event::Lsp(lsp_server::Message::Notification(not)) => {
- if notification_is::<lsp_types::notification::DidOpenTextDocument>(not)
- || notification_is::<lsp_types::notification::DidChangeTextDocument>(not)
- {
- return debug_non_verbose(not, f);
- }
+ Event::Lsp(lsp_server::Message::Notification(not))
+ if (notification_is::<lsp_types::notification::DidOpenTextDocument>(not)
+ || notification_is::<lsp_types::notification::DidChangeTextDocument>(not)) =>
+ {
+ return debug_non_verbose(not, f);
}
Event::Task(Task::Response(resp)) => {
return f
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs
index 157285d1b6..46ea4daba8 100644
--- a/crates/syntax/src/ast/edit_in_place.rs
+++ b/crates/syntax/src/ast/edit_in_place.rs
@@ -514,10 +514,11 @@ fn normalize_ws_between_braces(node: &SyntaxNode) -> Option<()> {
let indent = IndentLevel::from_node(node);
match l.next_sibling_or_token() {
- Some(ws) if ws.kind() == SyntaxKind::WHITESPACE => {
- if ws.next_sibling_or_token()?.into_token()? == r {
- ted::replace(ws, make::tokens::whitespace(&format!("\n{indent}")));
- }
+ Some(ws)
+ if ws.kind() == SyntaxKind::WHITESPACE
+ && ws.next_sibling_or_token()?.into_token()? == r =>
+ {
+ ted::replace(ws, make::tokens::whitespace(&format!("\n{indent}")));
}
Some(ws) if ws.kind() == T!['}'] => {
ted::insert(ted::Position::after(l), make::tokens::whitespace(&format!("\n{indent}")));
diff --git a/crates/syntax/src/syntax_editor.rs b/crates/syntax/src/syntax_editor.rs
index b2bd10b354..edd063ffd4 100644
--- a/crates/syntax/src/syntax_editor.rs
+++ b/crates/syntax/src/syntax_editor.rs
@@ -591,8 +591,8 @@ mod tests {
assert_eq!(edit.find_annotation(placeholder_snippet).len(), 2);
assert!(
edit.annotations
- .iter()
- .flat_map(|(_, elements)| elements)
+ .values()
+ .flatten()
.all(|element| element.ancestors().any(|it| &it == edit.new_root()))
)
}
diff --git a/crates/syntax/src/syntax_editor/edits.rs b/crates/syntax/src/syntax_editor/edits.rs
index 300d0f02ea..28e8ceed70 100644
--- a/crates/syntax/src/syntax_editor/edits.rs
+++ b/crates/syntax/src/syntax_editor/edits.rs
@@ -301,10 +301,11 @@ fn normalize_ws_between_braces(editor: &SyntaxEditor, node: &SyntaxNode) -> Opti
let indent = IndentLevel::from_node(node);
match l.next_sibling_or_token() {
- Some(ws) if ws.kind() == SyntaxKind::WHITESPACE => {
- if ws.next_sibling_or_token()?.into_token()? == r {
- editor.replace(ws, make.whitespace(&format!("\n{indent}")));
- }
+ Some(ws)
+ if ws.kind() == SyntaxKind::WHITESPACE
+ && ws.next_sibling_or_token()?.into_token()? == r =>
+ {
+ editor.replace(ws, make.whitespace(&format!("\n{indent}")));
}
Some(ws) if ws.kind() == T!['}'] => {
editor.insert(Position::after(l), make.whitespace(&format!("\n{indent}")));
diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs
index 05528505f2..122cf4887e 100644
--- a/xtask/src/tidy.rs
+++ b/xtask/src/tidy.rs
@@ -100,6 +100,10 @@ fn check_cargo_toml(path: &Path, text: String) {
if !text.contains("path=") {
continue;
}
+ #[expect(
+ clippy::collapsible_match,
+ reason = "this changes meaning, as `dev-dependencies` includes `dependencies`"
+ )]
match section {
Some(s) if s.contains("dev-dependencies") => {
if text.contains("version") {