Handle "calls" inside the closure as well in map_clone lint

This commit is contained in:
Guillaume Gomez 2024-01-07 13:13:29 +01:00
parent af35d37749
commit 78aa2e29e2

View file

@ -61,24 +61,37 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_
}
}
},
hir::ExprKind::Call(call, [_]) => {
if let hir::ExprKind::Path(qpath) = call.kind {
handle_path(cx, call, &qpath, e, recv);
}
},
_ => {},
}
},
_ => {},
}
},
hir::ExprKind::Path(qpath) => {
if let Some(path_def_id) = cx.qpath_res(&qpath, arg.hir_id).opt_def_id()
hir::ExprKind::Path(qpath) => handle_path(cx, arg, &qpath, e, recv),
_ => {},
}
}
}
fn handle_path(
cx: &LateContext<'_>,
arg: &hir::Expr<'_>,
qpath: &hir::QPath<'_>,
e: &hir::Expr<'_>,
recv: &hir::Expr<'_>,
) {
if let Some(path_def_id) = cx.qpath_res(qpath, arg.hir_id).opt_def_id()
&& match_def_path(cx, path_def_id, &paths::CLONE_TRAIT_METHOD)
{
// FIXME: It would be better to infer the type to check if it's copyable or not
// to suggest to use `.copied()` instead of `.cloned()` where applicable.
lint_path(cx, e.span, recv.span);
}
},
_ => {},
}
}
}
fn ident_eq(name: Ident, path: &hir::Expr<'_>) -> bool {