@@ -5,8 +5,9 @@ use rustc_span::sym;
55
66use crate :: {
77 lints:: {
8- DropCopyDiag , DropRefDiag , ForgetCopyDiag , ForgetRefDiag , IgnoreDropSuggestion ,
8+ DropCopyDiag , DropCopySuggestion , DropRefDiag , ForgetCopyDiag , ForgetRefDiag ,
99 UndroppedManuallyDropsDiag , UndroppedManuallyDropsSuggestion ,
10+ UseLetUnderscoreIgnoreSuggestion ,
1011 } ,
1112 LateContext , LateLintPass , LintContext ,
1213} ;
@@ -148,31 +149,37 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
148149 let arg_ty = cx. typeck_results ( ) . expr_ty ( arg) ;
149150 let is_copy = arg_ty. is_copy_modulo_regions ( cx. tcx , cx. param_env ) ;
150151 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
159164 }
160- } else {
161- IgnoreDropSuggestion :: Note
162165 } ;
163166 match fn_name {
164167 sym:: mem_drop if arg_ty. is_ref ( ) && !drop_is_single_call_in_arm => {
165168 cx. emit_span_lint (
166169 DROPPING_REFERENCES ,
167170 expr. span ,
168- DropRefDiag { arg_ty, label : arg. span , sugg } ,
171+ DropRefDiag { arg_ty, label : arg. span , sugg : let_underscore_ignore_sugg ( ) } ,
169172 ) ;
170173 }
171174 sym:: mem_forget if arg_ty. is_ref ( ) => {
172175 cx. emit_span_lint (
173176 FORGETTING_REFERENCES ,
174177 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+ } ,
176183 ) ;
177184 }
178185 sym:: mem_drop if is_copy && !drop_is_single_call_in_arm => {
@@ -199,7 +206,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
199206 cx. emit_span_lint (
200207 FORGETTING_COPY_TYPES ,
201208 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+ } ,
203214 ) ;
204215 }
205216 sym:: mem_drop
0 commit comments