Skip to content

Commit 78aa2e2

Browse files
Handle "calls" inside the closure as well in map_clone lint
1 parent af35d37 commit 78aa2e2

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

clippy_lints/src/methods/map_clone.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,39 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_
6161
}
6262
}
6363
},
64+
hir::ExprKind::Call(call, [_]) => {
65+
if let hir::ExprKind::Path(qpath) = call.kind {
66+
handle_path(cx, call, &qpath, e, recv);
67+
}
68+
},
6469
_ => {},
6570
}
6671
},
6772
_ => {},
6873
}
6974
},
70-
hir::ExprKind::Path(qpath) => {
71-
if let Some(path_def_id) = cx.qpath_res(&qpath, arg.hir_id).opt_def_id()
72-
&& match_def_path(cx, path_def_id, &paths::CLONE_TRAIT_METHOD)
73-
{
74-
// FIXME: It would be better to infer the type to check if it's copyable or not
75-
// to suggest to use `.copied()` instead of `.cloned()` where applicable.
76-
lint_path(cx, e.span, recv.span);
77-
}
78-
},
75+
hir::ExprKind::Path(qpath) => handle_path(cx, arg, &qpath, e, recv),
7976
_ => {},
8077
}
8178
}
8279
}
8380

81+
fn handle_path(
82+
cx: &LateContext<'_>,
83+
arg: &hir::Expr<'_>,
84+
qpath: &hir::QPath<'_>,
85+
e: &hir::Expr<'_>,
86+
recv: &hir::Expr<'_>,
87+
) {
88+
if let Some(path_def_id) = cx.qpath_res(qpath, arg.hir_id).opt_def_id()
89+
&& match_def_path(cx, path_def_id, &paths::CLONE_TRAIT_METHOD)
90+
{
91+
// FIXME: It would be better to infer the type to check if it's copyable or not
92+
// to suggest to use `.copied()` instead of `.cloned()` where applicable.
93+
lint_path(cx, e.span, recv.span);
94+
}
95+
}
96+
8497
fn ident_eq(name: Ident, path: &hir::Expr<'_>) -> bool {
8598
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = path.kind {
8699
path.segments.len() == 1 && path.segments[0].ident == name

0 commit comments

Comments
 (0)