@@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
7474 _: hir:: def_id:: LocalDefId ,
7575 ) {
7676 self . apas . clear ( ) ;
77- let initial_dummy_stmt = dummy_stmt_expr ( & body. value ) ;
77+ let initial_dummy_stmt = dummy_stmt_expr ( body. value ) ;
7878 let mut ap = AuxParams :: new ( & mut self . apas , & initial_dummy_stmt) ;
7979 StmtsChecker :: new ( & mut ap, cx, & mut self . seen_types , & mut self . type_cache ) . visit_body ( body) ;
8080 for apa in ap. apas . values ( ) {
@@ -93,13 +93,13 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
9393 let indent = " " . repeat ( indent_of ( cx, apa. last_stmt_span ) . unwrap_or ( 0 ) ) ;
9494 let init_method = snippet ( cx, apa. first_method_span , ".." ) ;
9595 let usage_method = snippet ( cx, apa. last_method_span , ".." ) ;
96- let stmt = if apa. last_bind_ident != Ident :: empty ( ) {
96+ let stmt = if apa. last_bind_ident == Ident :: empty ( ) {
97+ format ! ( "\n {indent}{init_method}.{usage_method};" )
98+ } else {
9799 format ! (
98100 "\n {indent}let {} = {init_method}.{usage_method};" ,
99101 snippet( cx, apa. last_bind_ident. span, ".." ) ,
100102 )
101- } else {
102- format ! ( "\n {indent}{init_method}.{usage_method};" )
103103 } ;
104104 diag. span_suggestion_verbose (
105105 apa. first_stmt_span ,
@@ -265,7 +265,7 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o
265265 fn visit_block ( & mut self , block : & ' tcx hir:: Block < ' tcx > ) {
266266 self . ap . curr_block_hir_id = block. hir_id ;
267267 self . ap . curr_block_span = block. span ;
268- for stmt in block. stmts . iter ( ) {
268+ for stmt in block. stmts {
269269 self . ap . curr_stmt = Cow :: Borrowed ( stmt) ;
270270 self . visit_stmt ( stmt) ;
271271 self . ap . curr_block_hir_id = block. hir_id ;
@@ -300,20 +300,22 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o
300300 }
301301 }
302302 {
303- let mut apa = AuxParamsAttr :: default ( ) ;
304- apa. first_bind_ident = ident;
305- apa. first_block_hir_id = self . ap . curr_block_hir_id ;
306- apa. first_block_span = self . ap . curr_block_span ;
307- apa. first_method_span = {
308- let expr_or_init = expr_or_init ( self . cx , expr) ;
309- if let hir:: ExprKind :: MethodCall ( _, local_expr, _, span) = expr_or_init. kind {
310- local_expr. span . to ( span)
311- }
312- else {
313- expr_or_init. span
314- }
303+ let mut apa = AuxParamsAttr {
304+ first_bind_ident : ident,
305+ first_block_hir_id : self . ap . curr_block_hir_id ,
306+ first_block_span : self . ap . curr_block_span ,
307+ first_method_span : {
308+ let expr_or_init = expr_or_init ( self . cx , expr) ;
309+ if let hir:: ExprKind :: MethodCall ( _, local_expr, _, span) = expr_or_init. kind {
310+ local_expr. span . to ( span)
311+ }
312+ else {
313+ expr_or_init. span
314+ }
315+ } ,
316+ first_stmt_span : self . ap . curr_stmt . span ,
317+ ..Default :: default ( )
315318 } ;
316- apa. first_stmt_span = self . ap . curr_stmt . span ;
317319 modify_apa_params ( & mut apa) ;
318320 let _ = self . ap . apas . insert ( hir_id, apa) ;
319321 } else {
@@ -445,9 +447,5 @@ fn has_drop(expr: &hir::Expr<'_>, first_bind_ident: &Ident) -> bool {
445447}
446448
447449fn is_expensive_expr ( expr : & hir:: Expr < ' _ > ) -> bool {
448- if let hir:: ExprKind :: Path ( _) = expr. kind {
449- false
450- } else {
451- true
452- }
450+ !matches ! ( expr. kind, hir:: ExprKind :: Path ( _) )
453451}
0 commit comments