From 2ff702cbb547ea02381820536b27a575f14ba59e Mon Sep 17 00:00:00 2001 From: ThibsG Date: Wed, 20 Oct 2021 22:18:12 +0200 Subject: [PATCH] Rephrase the fn checking for a double ref, not only one --- clippy_lints/src/methods/search_is_some.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index d08abc5b3..96e040d92 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -226,7 +226,7 @@ impl DerefDelegate<'_, 'tcx> { format!("{}{}", self.suggestion_start, end_snip) } - fn func_takes_arg_by_ref(&self, parent_expr: &'tcx hir::Expr<'_>, cmt_hir_id: HirId) -> bool { + fn func_takes_arg_by_double_ref(&self, parent_expr: &'tcx hir::Expr<'_>, cmt_hir_id: HirId) -> bool { let (call_args, inputs) = match parent_expr.kind { ExprKind::MethodCall(_, _, call_args, _) => { if let Some(method_did) = self.cx.typeck_results().type_dependent_def_id(parent_expr.hir_id) { @@ -277,16 +277,18 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { let arg_ty_kind = self.cx.typeck_results().expr_ty(expr).kind(); if matches!(arg_ty_kind, ty::Ref(_, _, Mutability::Not)) { - // suggest ampersand if call function is taking args by ref - let takes_arg_by_ref = self.func_takes_arg_by_ref(parent_expr, cmt.hir_id); + // suggest ampersand if call function is taking args by double reference + let takes_arg_by_double_ref = self.func_takes_arg_by_double_ref(parent_expr, cmt.hir_id); // do not suggest ampersand if the ident is the method caller - let ident_sugg = - if !call_args.is_empty() && call_args[0].hir_id == cmt.hir_id && !takes_arg_by_ref { - format!("{}{}", start_snip, ident_str) - } else { - format!("{}&{}", start_snip, ident_str) - }; + let ident_sugg = if !call_args.is_empty() + && call_args[0].hir_id == cmt.hir_id + && !takes_arg_by_double_ref + { + format!("{}{}", start_snip, ident_str) + } else { + format!("{}&{}", start_snip, ident_str) + }; self.suggestion_start.push_str(&ident_sugg); self.next_pos = span.hi(); return;