@@ -5,8 +5,9 @@ use rustc_span::sym;
5
5
6
6
use crate :: {
7
7
lints:: {
8
- DropCopyDiag , DropRefDiag , ForgetCopyDiag , ForgetRefDiag , IgnoreDropSuggestion ,
8
+ DropCopyDiag , DropCopySuggestion , DropRefDiag , ForgetCopyDiag , ForgetRefDiag ,
9
9
UndroppedManuallyDropsDiag , UndroppedManuallyDropsSuggestion ,
10
+ UseLetUnderscoreIgnoreSuggestion ,
10
11
} ,
11
12
LateContext , LateLintPass , LintContext ,
12
13
} ;
@@ -148,31 +149,37 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
148
149
let arg_ty = cx. typeck_results ( ) . expr_ty ( arg) ;
149
150
let is_copy = arg_ty. is_copy_modulo_regions ( cx. tcx , cx. param_env ) ;
150
151
let drop_is_single_call_in_arm = is_single_call_in_arm ( cx, arg, expr) ;
151
- let sugg = if let Some ( ( _, node) ) = cx. tcx . hir ( ) . parent_iter ( expr. hir_id ) . nth ( 0 )
152
- && let Node :: Stmt ( stmt) = node
153
- && let StmtKind :: Semi ( e) = stmt. kind
154
- && e. hir_id == expr. hir_id
155
- {
156
- IgnoreDropSuggestion :: Suggestion {
157
- start_span : expr. span . shrink_to_lo ( ) . until ( arg. span ) ,
158
- end_span : arg. span . shrink_to_hi ( ) . until ( expr. span . shrink_to_hi ( ) ) ,
152
+ let let_underscore_ignore_sugg = || {
153
+ if let Some ( ( _, node) ) = cx. tcx . hir ( ) . parent_iter ( expr. hir_id ) . nth ( 0 )
154
+ && let Node :: Stmt ( stmt) = node
155
+ && let StmtKind :: Semi ( e) = stmt. kind
156
+ && e. hir_id == expr. hir_id
157
+ {
158
+ UseLetUnderscoreIgnoreSuggestion :: Suggestion {
159
+ start_span : expr. span . shrink_to_lo ( ) . until ( arg. span ) ,
160
+ end_span : arg. span . shrink_to_hi ( ) . until ( expr. span . shrink_to_hi ( ) ) ,
161
+ }
162
+ } else {
163
+ UseLetUnderscoreIgnoreSuggestion :: Note
159
164
}
160
- } else {
161
- IgnoreDropSuggestion :: Note
162
165
} ;
163
166
match fn_name {
164
167
sym:: mem_drop if arg_ty. is_ref ( ) && !drop_is_single_call_in_arm => {
165
168
cx. emit_span_lint (
166
169
DROPPING_REFERENCES ,
167
170
expr. span ,
168
- DropRefDiag { arg_ty, label : arg. span , sugg } ,
171
+ DropRefDiag { arg_ty, label : arg. span , sugg : let_underscore_ignore_sugg ( ) } ,
169
172
) ;
170
173
}
171
174
sym:: mem_forget if arg_ty. is_ref ( ) => {
172
175
cx. emit_span_lint (
173
176
FORGETTING_REFERENCES ,
174
177
expr. span ,
175
- ForgetRefDiag { arg_ty, label : arg. span } ,
178
+ ForgetRefDiag {
179
+ arg_ty,
180
+ label : arg. span ,
181
+ sugg : let_underscore_ignore_sugg ( ) ,
182
+ } ,
176
183
) ;
177
184
}
178
185
sym:: mem_drop if is_copy && !drop_is_single_call_in_arm => {
@@ -199,7 +206,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
199
206
cx. emit_span_lint (
200
207
FORGETTING_COPY_TYPES ,
201
208
expr. span ,
202
- ForgetCopyDiag { arg_ty, label : arg. span , sugg } ,
209
+ ForgetCopyDiag {
210
+ arg_ty,
211
+ label : arg. span ,
212
+ sugg : let_underscore_ignore_sugg ( ) ,
213
+ } ,
203
214
) ;
204
215
}
205
216
sym:: mem_drop
0 commit comments