From 5a0078c9d1141e060c43a13d21bfcc83cc169111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 12 Mar 2022 15:57:57 +0100 Subject: [PATCH] more clippy fixes: clippy::search_is_some clippy::redundant_static_lifetimes clippy::match_single_binding clippy::match_ref_pats clippy::map_entry clippy::manual_map clippy::iter_overeager_cloned clippy::into_iter_on_ref clippy::extra_unused_lifetimes --- crates/hir_ty/src/consteval.rs | 6 ++--- crates/hir_ty/src/method_resolution.rs | 2 +- crates/ide/src/syntax_highlighting/inject.rs | 2 +- .../src/handlers/extract_module.rs | 23 +++++++------------ .../ide_assists/src/handlers/inline_call.rs | 2 +- crates/syntax/src/ast/expr_ext.rs | 4 +--- 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/crates/hir_ty/src/consteval.rs b/crates/hir_ty/src/consteval.rs index 958673600b..5cc474aca6 100644 --- a/crates/hir_ty/src/consteval.rs +++ b/crates/hir_ty/src/consteval.rs @@ -241,8 +241,8 @@ pub fn eval_const(expr: &Expr, ctx: &mut ConstEvalCtx<'_>) -> Result { let mut prev_values = HashMap::>::default(); for statement in &**statements { - match statement { - &hir_def::expr::Statement::Let { pat, initializer, .. } => { + match *statement { + hir_def::expr::Statement::Let { pat, initializer, .. } => { let pat = &ctx.pats[pat]; let name = match pat { Pat::Bind { name, subpat, .. } if subpat.is_none() => name.clone(), @@ -261,7 +261,7 @@ pub fn eval_const(expr: &Expr, ctx: &mut ConstEvalCtx<'_>) -> Result { + hir_def::expr::Statement::Expr { .. } => { return Err(ConstEvalError::NotSupported("this kind of statement")) } } diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 2d493b154f..6564a3f4c7 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs @@ -1105,7 +1105,7 @@ pub(crate) fn inherent_impl_substs( // Unknown, and in that case we want the result to contain Unknown in those // places again. let suffix = - Substitution::from_iter(Interner, substs.iter(Interner).cloned().skip(self_ty_vars)); + Substitution::from_iter(Interner, substs.iter(Interner).skip(self_ty_vars).cloned()); Some(fallback_bound_vars(suffix, self_ty_vars)) } diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index 7ac1200a4a..8af0d8007d 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs @@ -78,7 +78,7 @@ pub(super) fn ra_fixture( Some(()) } -const RUSTDOC_FENCE: &'static str = "```"; +const RUSTDOC_FENCE: &str = "```"; /// Injection of syntax highlighting of doctests. pub(super) fn doc_comment( diff --git a/crates/ide_assists/src/handlers/extract_module.rs b/crates/ide_assists/src/handlers/extract_module.rs index ffe4c74e0a..38815730b1 100644 --- a/crates/ide_assists/src/handlers/extract_module.rs +++ b/crates/ide_assists/src/handlers/extract_module.rs @@ -195,11 +195,11 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<( // Remove complete impl block if it has only one child (as such it will be empty // after deleting that child) if impl_child_count == 1 { - node_to_be_removed = impl_.syntax() + node_to_be_removed = impl_.syntax(); } else { //Remove selected node node_to_be_removed = &node; - } + }; builder.delete(node_to_be_removed.text_range()); // Remove preceding indentation from node @@ -418,11 +418,8 @@ impl Module { record_field_parents.into_iter().for_each(|x| { x.1.descendants().filter_map(ast::RecordField::cast).for_each(|desc| { - let is_record_field_present = record_fields - .clone() - .into_iter() - .find(|x| x.to_string() == desc.to_string()) - .is_some(); + let is_record_field_present = + record_fields.clone().into_iter().any(|x| x.to_string() == desc.to_string()); if is_record_field_present { replacements.push((desc.visibility(), desc.syntax().clone())); } @@ -520,7 +517,7 @@ impl Module { let mut exists_inside_sel = false; let mut exists_outside_sel = false; usage_res.clone().into_iter().for_each(|x| { - let mut non_use_nodes_itr = (&x.1).into_iter().filter_map(|x| { + let mut non_use_nodes_itr = (&x.1).iter().filter_map(|x| { if find_node_at_range::(file.syntax(), x.range).is_none() { let path_opt = find_node_at_range::(file.syntax(), x.range); return path_opt; @@ -531,15 +528,11 @@ impl Module { if non_use_nodes_itr .clone() - .find(|x| !selection_range.contains_range(x.syntax().text_range())) - .is_some() + .any(|x| !selection_range.contains_range(x.syntax().text_range())) { exists_outside_sel = true; } - if non_use_nodes_itr - .find(|x| selection_range.contains_range(x.syntax().text_range())) - .is_some() - { + if non_use_nodes_itr.any(|x| selection_range.contains_range(x.syntax().text_range())) { exists_inside_sel = true; } }); @@ -556,7 +549,7 @@ impl Module { let file_id = x.0; let mut use_opt: Option = None; if file_id == curr_file_id { - (&x.1).into_iter().for_each(|x| { + (&x.1).iter().for_each(|x| { let node_opt: Option = find_node_at_range(file.syntax(), x.range); if let Some(node) = node_opt { use_opt = Some(node); diff --git a/crates/ide_assists/src/handlers/inline_call.rs b/crates/ide_assists/src/handlers/inline_call.rs index 1bcddeb9ac..994d78303f 100644 --- a/crates/ide_assists/src/handlers/inline_call.rs +++ b/crates/ide_assists/src/handlers/inline_call.rs @@ -374,7 +374,7 @@ fn inline( // inline direct local arguments [_, ..] if expr_as_name_ref(expr).is_some() => { cov_mark::hit!(inline_call_inline_locals); - usages.into_iter().for_each(|usage| inline_direct(usage, expr)); + usages.iter().for_each(|usage| inline_direct(usage, expr)); } // can't inline, emit a let statement _ => { diff --git a/crates/syntax/src/ast/expr_ext.rs b/crates/syntax/src/ast/expr_ext.rs index ae3a3c9393..1d0f393ec1 100644 --- a/crates/syntax/src/ast/expr_ext.rs +++ b/crates/syntax/src/ast/expr_ext.rs @@ -392,10 +392,8 @@ impl AstNode for CallableExpr { { if let Some(it) = ast::CallExpr::cast(syntax.clone()) { Some(Self::Call(it)) - } else if let Some(it) = ast::MethodCallExpr::cast(syntax) { - Some(Self::MethodCall(it)) } else { - None + ast::MethodCallExpr::cast(syntax).map(Self::MethodCall) } }