- if path.segments.len() == 1 && path.segments[0].ident == name {
- let mut applicability = Applicability::MachineApplicable;
- span_lint_and_sugg(
- cx,
- MAP_CLONE,
- replace,
- "You are using an explicit closure for cloning elements",
- "Consider calling the dedicated `cloned` method",
- format!(
- "{}.cloned()",
- snippet_with_applicability(cx, root, "..", &mut applicability)
- ),
- applicability,
- )
- }
+ path.segments.len() == 1 && path.segments[0].ident == name
+ } else {
+ false
+ }
+}
+
+fn lint_needless_cloning(cx: &LateContext<'_, '_>, root: Span, receiver: Span) {
+ span_lint_and_sugg(
+ cx,
+ MAP_CLONE,
+ root.trim_start(receiver).unwrap(),
+ "You are needlessly cloning iterator elements",
+ "Remove the map call",
+ String::new(),
+ Applicability::MachineApplicable,
+ )
+}
+
+fn lint(cx: &LateContext<'_, '_>, replace: Span, root: Span, copied: bool) {
+ let mut applicability = Applicability::MachineApplicable;
+ if copied {
+ span_lint_and_sugg(
+ cx,
+ MAP_CLONE,
+ replace,
+ "You are using an explicit closure for copying elements",
+ "Consider calling the dedicated `copied` method",
+ format!(
+ "{}.copied()",
+ snippet_with_applicability(cx, root, "..", &mut applicability)
+ ),
+ applicability,
+ )
+ } else {
+ span_lint_and_sugg(
+ cx,
+ MAP_CLONE,
+ replace,
+ "You are using an explicit closure for cloning elements",
+ "Consider calling the dedicated `cloned` method",
+ format!(
+ "{}.cloned()",
+ snippet_with_applicability(cx, root, "..", &mut applicability)
+ ),
+ applicability,
+ )