@@ -83,11 +83,11 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
8383            let  emit_sugg = |diag :  & mut  Diag < ' _ ,  _ > | match  apa. counter  { 
8484                0  | 1  => { } , 
8585                2  => { 
86-                     if  let   Some ( last_stmt_span )  =  apa. last_stmt_span  { 
87-                         if  let   Some ( last_method_span )  =  apa. last_method_span  { 
88-                             let  indent = " " . repeat ( indent_of ( cx,  last_stmt_span) . unwrap_or ( 0 ) ) ; 
86+                     if  ! apa. last_stmt_span . is_dummy ( )  { 
87+                         if  ! apa. last_method_span . is_dummy ( )  { 
88+                             let  indent = " " . repeat ( indent_of ( cx,  apa . last_stmt_span ) . unwrap_or ( 0 ) ) ; 
8989                            let  init_method = snippet ( cx,  apa. first_method_span ,  ".." ) ; 
90-                             let  usage_method = snippet ( cx,  last_method_span,  ".." ) ; 
90+                             let  usage_method = snippet ( cx,  apa . last_method_span ,  ".." ) ; 
9191                            let  stmt = if  let  Some ( last_bind_ident)  = apa. last_bind_ident  { 
9292                                format ! ( 
9393                                    "\n {indent}let {} = {init_method}.{usage_method};" , 
@@ -98,23 +98,23 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
9898                            } ; 
9999                            diag. multipart_suggestion_verbose ( 
100100                                "merge the temporary construction with its single usage" , 
101-                                 vec ! [ ( apa. first_stmt_span,  stmt) ,  ( last_stmt_span,  String :: new( ) ) ] , 
101+                                 vec ! [ ( apa. first_stmt_span,  stmt) ,  ( apa . last_stmt_span,  String :: new( ) ) ] , 
102102                                Applicability :: MaybeIncorrect , 
103103                            ) ; 
104104                        }  else  { 
105105                            diag. help ( "merge the temporary construction with its single usage" ) ; 
106-                             diag. span_note ( last_stmt_span,  "single usage here" ) ; 
106+                             diag. span_note ( apa . last_stmt_span ,  "single usage here" ) ; 
107107                        } 
108108                    } 
109109                } , 
110110                _ => { 
111-                     if  let   Some ( last_stmt_span )  =  apa. last_stmt_span  { 
111+                     if  ! apa. last_stmt_span . is_dummy ( )  { 
112112                        diag. span_suggestion ( 
113-                             last_stmt_span. shrink_to_hi ( ) , 
113+                             apa . last_stmt_span . shrink_to_hi ( ) , 
114114                            "drop the temporary after the end of its last usage" , 
115115                            format ! ( 
116116                                "\n {}drop({});" , 
117-                                 " " . repeat( indent_of( cx,  last_stmt_span) . unwrap_or( 0 ) ) , 
117+                                 " " . repeat( indent_of( cx,  apa . last_stmt_span) . unwrap_or( 0 ) ) , 
118118                                first_bind_ident
119119                            ) , 
120120                            Applicability :: MaybeIncorrect , 
@@ -238,19 +238,15 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> StmtsChecker<'ap, 'lc, 'others, 'stmt, 'tcx
238238        } ; 
239239        if  has_expensive_stmt { 
240240            for  apa in  self . ap . apas . values_mut ( )  { 
241+                 let  last_stmt_is_not_dummy = apa. last_stmt_span  != DUMMY_SP ; 
242+                 let  last_stmt_is_not_curr = self . ap . curr_stmt . span  != apa. last_stmt_span ; 
241243                let  block_equals_curr = self . ap . curr_block_hir_id  == apa. first_block_hir_id ; 
242244                let  block_is_ancestor = self 
243245                    . cx 
244246                    . tcx 
245247                    . hir_parent_iter ( self . ap . curr_block_hir_id ) 
246248                    . any ( |( id,  _) | id == apa. first_block_hir_id ) ; 
247-                 // last stmt is not dummy 
248-                 if  let  Some ( last_stmt_span)  = apa. last_stmt_span 
249-                     && !last_stmt_span. is_dummy ( ) 
250-                     // last stmt is not current 
251-                     && last_stmt_span != self . ap . curr_stmt . span 
252-                     && ( block_equals_curr || block_is_ancestor) 
253-                 { 
249+                 if  last_stmt_is_not_dummy && last_stmt_is_not_curr && ( block_equals_curr || block_is_ancestor)  { 
254250                    apa. has_expensive_expr_after_last_attr  = true ; 
255251                } 
256252            } 
@@ -290,10 +286,6 @@ impl<'tcx> Visitor<'tcx> for StmtsChecker<'_, '_, '_, '_, 'tcx> {
290286                && !self . ap . apas . contains_key ( & hir_id) 
291287                && path_to_local ( expr) . is_none_or ( |local_hir_id| local_hir_id == hir_id) 
292288            { 
293-                 #[ expect(  
294-                     clippy:: inconsistent_struct_constructor,  
295-                     reason = "grouping fields with default values at the end"  
296-                 ) ]  
297289                let  mut  apa = AuxParamsAttr  { 
298290                    first_block_hir_id :  self . ap . curr_block_hir_id , 
299291                    first_block_span :  self . ap . curr_block_span , 
@@ -307,12 +299,7 @@ impl<'tcx> Visitor<'tcx> for StmtsChecker<'_, '_, '_, '_, 'tcx> {
307299                        } 
308300                    } , 
309301                    first_stmt_span :  self . ap . curr_stmt . span , 
310-                     // default values 
311-                     counter :  0 , 
312-                     has_expensive_expr_after_last_attr :  false , 
313-                     last_bind_ident :  None , 
314-                     last_method_span :  None , 
315-                     last_stmt_span :  None , 
302+                     ..Default :: default ( ) 
316303                } ; 
317304                modify_apa_params ( & mut  apa) ; 
318305                let  _ = self . ap . apas . insert ( hir_id,  apa) ; 
@@ -331,22 +318,22 @@ impl<'tcx> Visitor<'tcx> for StmtsChecker<'_, '_, '_, '_, 'tcx> {
331318                        if  let  Some ( local_init)  = local. init 
332319                            && let  hir:: ExprKind :: MethodCall ( _,  _,  _,  span)  = local_init. kind 
333320                        { 
334-                             apa. last_method_span  = Some ( span) ; 
321+                             apa. last_method_span  = span; 
335322                        } 
336323                    } , 
337324                    hir:: StmtKind :: Semi ( semi_expr)  => { 
338325                        if  has_drop ( semi_expr,  apa. first_bind_ident ,  self . cx )  { 
339326                            apa. has_expensive_expr_after_last_attr  = false ; 
340-                             apa. last_stmt_span  = None ; 
327+                             apa. last_stmt_span  = DUMMY_SP ; 
341328                            return ; 
342329                        } 
343330                        if  let  hir:: ExprKind :: MethodCall ( _,  _,  _,  span)  = semi_expr. kind  { 
344-                             apa. last_method_span  = Some ( span) ; 
331+                             apa. last_method_span  = span; 
345332                        } 
346333                    } , 
347334                    _ => { } , 
348335                } 
349-                 apa. last_stmt_span  = Some ( self . ap . curr_stmt . span ) ; 
336+                 apa. last_stmt_span  = self . ap . curr_stmt . span ; 
350337                modify_apa_params ( apa) ; 
351338            } 
352339        } 
@@ -402,9 +389,26 @@ struct AuxParamsAttr {
402389     /// marked with `#[has_significant_drop]`. 
403390     last_bind_ident :  Option < Ident > , 
404391    /// Similar to `last_bind_span` but encompasses the right-hand method call. 
405-      last_method_span :  Option < Span > , 
392+      last_method_span :  Span , 
406393    /// Similar to `last_bind_span` but encompasses the whole contained statement. 
407-      last_stmt_span :  Option < Span > , 
394+      last_stmt_span :  Span , 
395+ } 
396+ 
397+ impl  Default  for  AuxParamsAttr  { 
398+     fn  default ( )  -> Self  { 
399+         Self  { 
400+             counter :  0 , 
401+             has_expensive_expr_after_last_attr :  false , 
402+             first_block_hir_id :  HirId :: INVALID , 
403+             first_block_span :  DUMMY_SP , 
404+             first_bind_ident :  None , 
405+             first_method_span :  DUMMY_SP , 
406+             first_stmt_span :  DUMMY_SP , 
407+             last_bind_ident :  None , 
408+             last_method_span :  DUMMY_SP , 
409+             last_stmt_span :  DUMMY_SP , 
410+         } 
411+     } 
408412} 
409413
410414fn  dummy_stmt_expr < ' any > ( expr :  & ' any  hir:: Expr < ' any > )  -> hir:: Stmt < ' any >  { 
0 commit comments