@@ -69,15 +69,48 @@ fn main() {
69
69
//~^ ERROR: you are explicitly cloning with `.map()`
70
70
let y = x. map ( Clone :: clone) ;
71
71
//~^ ERROR: you are explicitly cloning with `.map()`
72
+ //~| HELP: consider calling the dedicated `cloned` method
72
73
let y = x. map ( String :: clone) ;
73
74
//~^ ERROR: you are explicitly cloning with `.map()`
75
+ //~| HELP: consider calling the dedicated `cloned` method
76
+
77
+ let x: Option < u32 > = Some ( 0 ) ;
78
+ let x = x. as_ref ( ) ; // We do this to prevent triggering the `useless_asref` lint.
79
+ let y = x. map ( |x| u32:: clone ( x) ) ;
80
+ //~^ ERROR: you are explicitly cloning with `.map()`
81
+ //~| HELP: consider calling the dedicated `copied` method
82
+ let y = x. map ( |x| Clone :: clone ( x) ) ;
83
+ //~^ ERROR: you are explicitly cloning with `.map()`
84
+ //~| HELP: consider calling the dedicated `copied` method
85
+
86
+ // Should not suggest `copied` or `cloned` here since `T` is not a reference.
87
+ let x: Option < u32 > = Some ( 0 ) ;
88
+ let y = x. map ( |x| u32:: clone ( & x) ) ;
89
+ let y = x. map ( |x| Clone :: clone ( & x) ) ;
74
90
75
91
// Testing with `Result` now.
76
92
let x: Result < String , ( ) > = Ok ( String :: new ( ) ) ;
77
93
let x = x. as_ref ( ) ; // We do this to prevent triggering the `useless_asref` lint.
78
94
let y = x. map ( |x| String :: clone ( x) ) ;
79
95
//~^ ERROR: you are explicitly cloning with `.map()`
80
- let y = x. map ( |x| String :: clone ( x) ) ;
96
+ //~| HELP: consider calling the dedicated `cloned` method
97
+ let y = x. map ( |x| Clone :: clone ( x) ) ;
98
+ //~^ ERROR: you are explicitly cloning with `.map()`
99
+ //~| HELP: consider calling the dedicated `cloned` method
100
+
101
+ let x: Result < u32 , ( ) > = Ok ( 0 ) ;
102
+ let x = x. as_ref ( ) ; // We do this to prevent triggering the `useless_asref` lint.
103
+ let y = x. map ( |x| u32:: clone ( x) ) ;
104
+ //~^ ERROR: you are explicitly cloning with `.map()`
105
+ //~| HELP: consider calling the dedicated `copied` method
106
+ let y = x. map ( |x| Clone :: clone ( x) ) ;
107
+ //~^ ERROR: you are explicitly cloning with `.map()`
108
+ //~| HELP: consider calling the dedicated `copied` method
109
+
110
+ // Should not suggest `copied` or `cloned` here since `T` is not a reference.
111
+ let x: Result < u32 , ( ) > = Ok ( 0 ) ;
112
+ let y = x. map ( |x| u32:: clone ( & x) ) ;
113
+ let y = x. map ( |x| Clone :: clone ( & x) ) ;
81
114
82
115
// We ensure that no warning is emitted here because `useless_asref` is taking over.
83
116
let x = Some ( String :: new ( ) ) ;
0 commit comments