@@ -4,8 +4,8 @@ use rustc_span::sym;
4
4
5
5
use crate :: {
6
6
lints:: {
7
- DropCopyDiag , DropRefDiag , ForgetCopyDiag , ForgetRefDiag , IgnoreDropSuggestion ,
8
- UndroppedManuallyDropsDiag , UndroppedManuallyDropsSuggestion ,
7
+ DropCopyDiag , DropRefDiag , ForgetCopyDiag , ForgetRefDiag , UndroppedManuallyDropsDiag ,
8
+ UndroppedManuallyDropsSuggestion , UseLetUnderscoreIgnoreSuggestion ,
9
9
} ,
10
10
LateContext , LateLintPass , LintContext ,
11
11
} ;
@@ -147,31 +147,37 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
147
147
let arg_ty = cx. typeck_results ( ) . expr_ty ( arg) ;
148
148
let is_copy = arg_ty. is_copy_modulo_regions ( cx. tcx , cx. param_env ) ;
149
149
let drop_is_single_call_in_arm = is_single_call_in_arm ( cx, arg, expr) ;
150
- let sugg = if let Some ( ( _, node) ) = cx. tcx . hir ( ) . parent_iter ( expr. hir_id ) . nth ( 0 )
151
- && let Node :: Stmt ( stmt) = node
152
- && let StmtKind :: Semi ( e) = stmt. kind
153
- && e. hir_id == expr. hir_id
154
- {
155
- IgnoreDropSuggestion :: Suggestion {
156
- start_span : expr. span . shrink_to_lo ( ) . until ( arg. span ) ,
157
- end_span : arg. span . shrink_to_hi ( ) . until ( expr. span . shrink_to_hi ( ) ) ,
150
+ let let_underscore_ignore_sugg = || {
151
+ 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
+ UseLetUnderscoreIgnoreSuggestion :: 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 ( ) ) ,
159
+ }
160
+ } else {
161
+ UseLetUnderscoreIgnoreSuggestion :: Note
158
162
}
159
- } else {
160
- IgnoreDropSuggestion :: Note
161
163
} ;
162
164
match fn_name {
163
165
sym:: mem_drop if arg_ty. is_ref ( ) && !drop_is_single_call_in_arm => {
164
166
cx. emit_span_lint (
165
167
DROPPING_REFERENCES ,
166
168
expr. span ,
167
- DropRefDiag { arg_ty, label : arg. span , sugg } ,
169
+ DropRefDiag { arg_ty, label : arg. span , sugg : let_underscore_ignore_sugg ( ) } ,
168
170
) ;
169
171
}
170
172
sym:: mem_forget if arg_ty. is_ref ( ) => {
171
173
cx. emit_span_lint (
172
174
FORGETTING_REFERENCES ,
173
175
expr. span ,
174
- ForgetRefDiag { arg_ty, label : arg. span } ,
176
+ ForgetRefDiag {
177
+ arg_ty,
178
+ label : arg. span ,
179
+ sugg : let_underscore_ignore_sugg ( ) ,
180
+ } ,
175
181
) ;
176
182
}
177
183
sym:: mem_drop if is_copy && !drop_is_single_call_in_arm => {
@@ -185,7 +191,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
185
191
cx. emit_span_lint (
186
192
FORGETTING_COPY_TYPES ,
187
193
expr. span ,
188
- ForgetCopyDiag { arg_ty, label : arg. span , sugg } ,
194
+ ForgetCopyDiag {
195
+ arg_ty,
196
+ label : arg. span ,
197
+ sugg : let_underscore_ignore_sugg ( ) ,
198
+ } ,
189
199
) ;
190
200
}
191
201
sym:: mem_drop
0 commit comments