diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index 652d2b80081..33b77cdc33d 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -18,6 +18,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_ if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && (cx.tcx.impl_of_method(method_id).map_or(false, |id| { is_type_diagnostic_item(cx, cx.tcx.type_of(id).instantiate_identity(), sym::Option) + || is_type_diagnostic_item(cx, cx.tcx.type_of(id).instantiate_identity(), sym::Result) }) || is_diag_trait_item(cx, method_id, sym::Iterator)) { match arg.kind { diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed index 74e4ea5ce01..144c42a1cb6 100644 --- a/tests/ui/map_clone.fixed +++ b/tests/ui/map_clone.fixed @@ -70,4 +70,10 @@ fn main() { //~^ ERROR: you are explicitly cloning with `.map()` let y = x.cloned(); //~^ ERROR: you are explicitly cloning with `.map()` + + // Testing with `Result` now. + let x: Result = Ok(String::new()); + let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. + let y = x.cloned(); + //~^ ERROR: you are explicitly cloning with `.map()` } diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index 0aac8024f67..e264d8ffc53 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -70,4 +70,10 @@ fn main() { //~^ ERROR: you are explicitly cloning with `.map()` let y = x.map(String::clone); //~^ ERROR: you are explicitly cloning with `.map()` + + // Testing with `Result` now. + let x: Result = Ok(String::new()); + let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. + let y = x.map(|x| String::clone(x)); + //~^ ERROR: you are explicitly cloning with `.map()` } diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr index aae4dae634a..7c6dc08f604 100644 --- a/tests/ui/map_clone.stderr +++ b/tests/ui/map_clone.stderr @@ -55,5 +55,11 @@ error: you are explicitly cloning with `.map()` LL | let y = x.map(String::clone); | ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` -error: aborting due to 9 previous errors +error: you are explicitly cloning with `.map()` + --> $DIR/map_clone.rs:77:13 + | +LL | let y = x.map(|x| String::clone(x)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` + +error: aborting due to 10 previous errors