@@ -73,14 +73,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
73
73
hir:: BindingAnnotation :: Unannotated , .., name, None
74
74
) = inner. node {
75
75
if ident_eq( name, closure_expr) {
76
- lint( cx, e. span, args[ 0 ] . span) ;
76
+ lint( cx, e. span, args[ 0 ] . span, true ) ;
77
77
}
78
78
} ,
79
79
hir:: PatKind :: Binding ( hir:: BindingAnnotation :: Unannotated , .., name, None ) => {
80
80
match closure_expr. node {
81
81
hir:: ExprKind :: Unary ( hir:: UnOp :: UnDeref , ref inner) => {
82
82
if ident_eq( name, inner) && !cx. tables. expr_ty( inner) . is_box( ) {
83
- lint( cx, e. span, args[ 0 ] . span) ;
83
+ lint( cx, e. span, args[ 0 ] . span, true ) ;
84
84
}
85
85
} ,
86
86
hir:: ExprKind :: MethodCall ( ref method, _, ref obj) => {
@@ -89,7 +89,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
89
89
90
90
let obj_ty = cx. tables. expr_ty( & obj[ 0 ] ) ;
91
91
if let ty:: Ref ( ..) = obj_ty. sty {
92
- lint( cx, e. span, args[ 0 ] . span) ;
92
+ lint( cx, e. span, args[ 0 ] . span, false ) ;
93
93
} else {
94
94
lint_needless_cloning( cx, e. span, args[ 0 ] . span) ;
95
95
}
@@ -125,18 +125,33 @@ fn lint_needless_cloning(cx: &LateContext<'_, '_>, root: Span, receiver: Span) {
125
125
)
126
126
}
127
127
128
- fn lint ( cx : & LateContext < ' _ , ' _ > , replace : Span , root : Span ) {
128
+ fn lint ( cx : & LateContext < ' _ , ' _ > , replace : Span , root : Span , copied : bool ) {
129
129
let mut applicability = Applicability :: MachineApplicable ;
130
- span_lint_and_sugg (
131
- cx,
132
- MAP_CLONE ,
133
- replace,
134
- "You are using an explicit closure for cloning elements" ,
135
- "Consider calling the dedicated `cloned` method" ,
136
- format ! (
137
- "{}.cloned()" ,
138
- snippet_with_applicability( cx, root, ".." , & mut applicability)
139
- ) ,
140
- applicability,
141
- )
130
+ if copied {
131
+ span_lint_and_sugg (
132
+ cx,
133
+ MAP_CLONE ,
134
+ replace,
135
+ "You are using an explicit closure for copying elements" ,
136
+ "Consider calling the dedicated `copied` method" ,
137
+ format ! (
138
+ "{}.copied()" ,
139
+ snippet_with_applicability( cx, root, ".." , & mut applicability)
140
+ ) ,
141
+ applicability,
142
+ )
143
+ } else {
144
+ span_lint_and_sugg (
145
+ cx,
146
+ MAP_CLONE ,
147
+ replace,
148
+ "You are using an explicit closure for cloning elements" ,
149
+ "Consider calling the dedicated `cloned` method" ,
150
+ format ! (
151
+ "{}.cloned()" ,
152
+ snippet_with_applicability( cx, root, ".." , & mut applicability)
153
+ ) ,
154
+ applicability,
155
+ )
156
+ }
142
157
}
0 commit comments