Skip to content

Commit 2ff702c

Browse files
committed
Rephrase the fn checking for a double ref, not only one
1 parent 7221999 commit 2ff702c

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

clippy_lints/src/methods/search_is_some.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl DerefDelegate<'_, 'tcx> {
226226
format!("{}{}", self.suggestion_start, end_snip)
227227
}
228228

229-
fn func_takes_arg_by_ref(&self, parent_expr: &'tcx hir::Expr<'_>, cmt_hir_id: HirId) -> bool {
229+
fn func_takes_arg_by_double_ref(&self, parent_expr: &'tcx hir::Expr<'_>, cmt_hir_id: HirId) -> bool {
230230
let (call_args, inputs) = match parent_expr.kind {
231231
ExprKind::MethodCall(_, _, call_args, _) => {
232232
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> {
277277
let arg_ty_kind = self.cx.typeck_results().expr_ty(expr).kind();
278278

279279
if matches!(arg_ty_kind, ty::Ref(_, _, Mutability::Not)) {
280-
// suggest ampersand if call function is taking args by ref
281-
let takes_arg_by_ref = self.func_takes_arg_by_ref(parent_expr, cmt.hir_id);
280+
// suggest ampersand if call function is taking args by double reference
281+
let takes_arg_by_double_ref = self.func_takes_arg_by_double_ref(parent_expr, cmt.hir_id);
282282

283283
// do not suggest ampersand if the ident is the method caller
284-
let ident_sugg =
285-
if !call_args.is_empty() && call_args[0].hir_id == cmt.hir_id && !takes_arg_by_ref {
286-
format!("{}{}", start_snip, ident_str)
287-
} else {
288-
format!("{}&{}", start_snip, ident_str)
289-
};
284+
let ident_sugg = if !call_args.is_empty()
285+
&& call_args[0].hir_id == cmt.hir_id
286+
&& !takes_arg_by_double_ref
287+
{
288+
format!("{}{}", start_snip, ident_str)
289+
} else {
290+
format!("{}&{}", start_snip, ident_str)
291+
};
290292
self.suggestion_start.push_str(&ident_sugg);
291293
self.next_pos = span.hi();
292294
return;

0 commit comments

Comments
 (0)