@@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
74
74
_: hir:: def_id:: LocalDefId ,
75
75
) {
76
76
self . apas . clear ( ) ;
77
- let initial_dummy_stmt = dummy_stmt_expr ( & body. value ) ;
77
+ let initial_dummy_stmt = dummy_stmt_expr ( body. value ) ;
78
78
let mut ap = AuxParams :: new ( & mut self . apas , & initial_dummy_stmt) ;
79
79
StmtsChecker :: new ( & mut ap, cx, & mut self . seen_types , & mut self . type_cache ) . visit_body ( body) ;
80
80
for apa in ap. apas . values ( ) {
@@ -93,13 +93,13 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
93
93
let indent = " " . repeat ( indent_of ( cx, apa. last_stmt_span ) . unwrap_or ( 0 ) ) ;
94
94
let init_method = snippet ( cx, apa. first_method_span , ".." ) ;
95
95
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 {
97
99
format ! (
98
100
"\n {indent}let {} = {init_method}.{usage_method};" ,
99
101
snippet( cx, apa. last_bind_ident. span, ".." ) ,
100
102
)
101
- } else {
102
- format ! ( "\n {indent}{init_method}.{usage_method};" )
103
103
} ;
104
104
diag. span_suggestion_verbose (
105
105
apa. first_stmt_span ,
@@ -265,7 +265,7 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o
265
265
fn visit_block ( & mut self , block : & ' tcx hir:: Block < ' tcx > ) {
266
266
self . ap . curr_block_hir_id = block. hir_id ;
267
267
self . ap . curr_block_span = block. span ;
268
- for stmt in block. stmts . iter ( ) {
268
+ for stmt in block. stmts {
269
269
self . ap . curr_stmt = Cow :: Borrowed ( stmt) ;
270
270
self . visit_stmt ( stmt) ;
271
271
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
300
300
}
301
301
}
302
302
{
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 ( )
315
318
} ;
316
- apa. first_stmt_span = self . ap . curr_stmt . span ;
317
319
modify_apa_params ( & mut apa) ;
318
320
let _ = self . ap . apas . insert ( hir_id, apa) ;
319
321
} else {
@@ -445,9 +447,5 @@ fn has_drop(expr: &hir::Expr<'_>, first_bind_ident: &Ident) -> bool {
445
447
}
446
448
447
449
fn 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 ( _) )
453
451
}
0 commit comments