@@ -4,8 +4,8 @@ use rustc_span::sym;
44
55use crate :: {
66 lints:: {
7- DropCopyDiag , DropRefDiag , ForgetCopyDiag , ForgetRefDiag , IgnoreDropSuggestion ,
8- UndroppedManuallyDropsDiag , UndroppedManuallyDropsSuggestion ,
7+ DropCopyDiag , DropRefDiag , ForgetCopyDiag , ForgetRefDiag , UndroppedManuallyDropsDiag ,
8+ UndroppedManuallyDropsSuggestion , UseLetUnderscoreIgnoreSuggestion ,
99 } ,
1010 LateContext , LateLintPass , LintContext ,
1111} ;
@@ -147,31 +147,37 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
147147 let arg_ty = cx. typeck_results ( ) . expr_ty ( arg) ;
148148 let is_copy = arg_ty. is_copy_modulo_regions ( cx. tcx , cx. param_env ) ;
149149 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
158162 }
159- } else {
160- IgnoreDropSuggestion :: Note
161163 } ;
162164 match fn_name {
163165 sym:: mem_drop if arg_ty. is_ref ( ) && !drop_is_single_call_in_arm => {
164166 cx. emit_span_lint (
165167 DROPPING_REFERENCES ,
166168 expr. span ,
167- DropRefDiag { arg_ty, label : arg. span , sugg } ,
169+ DropRefDiag { arg_ty, label : arg. span , sugg : let_underscore_ignore_sugg ( ) } ,
168170 ) ;
169171 }
170172 sym:: mem_forget if arg_ty. is_ref ( ) => {
171173 cx. emit_span_lint (
172174 FORGETTING_REFERENCES ,
173175 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+ } ,
175181 ) ;
176182 }
177183 sym:: mem_drop if is_copy && !drop_is_single_call_in_arm => {
@@ -185,7 +191,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
185191 cx. emit_span_lint (
186192 FORGETTING_COPY_TYPES ,
187193 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+ } ,
189199 ) ;
190200 }
191201 sym:: mem_drop
0 commit comments