@@ -438,13 +438,16 @@ impl<'a, 'tcx> Visitor<'tcx> for DeclMarker<'a, 'tcx> {
438
438
}
439
439
440
440
struct StatementDeclMarker < ' a , ' tcx > {
441
- used_locals : IndexVec < Local , usize > ,
441
+ used_locals : & ' a mut IndexVec < Local , usize > ,
442
442
statement : & ' a Statement < ' tcx > ,
443
443
}
444
444
445
445
impl < ' a , ' tcx > StatementDeclMarker < ' a , ' tcx > {
446
- pub fn new ( local_count : usize , statement : & ' a Statement < ' tcx > ) -> Self {
447
- Self { used_locals : IndexVec :: from_elem_n ( 0 , local_count) , statement }
446
+ pub fn new (
447
+ used_locals : & ' a mut IndexVec < Local , usize > ,
448
+ statement : & ' a Statement < ' tcx > ,
449
+ ) -> Self {
450
+ Self { used_locals, statement }
448
451
}
449
452
}
450
453
@@ -457,7 +460,11 @@ impl<'a, 'tcx> Visitor<'tcx> for StatementDeclMarker<'a, 'tcx> {
457
460
}
458
461
}
459
462
460
- self . used_locals [ * local] += 1 ;
463
+ let use_count = & mut self . used_locals [ * local] ;
464
+ // If this is the local we're removing...
465
+ if * use_count != 0 {
466
+ * use_count -= 1 ;
467
+ }
461
468
}
462
469
}
463
470
@@ -504,17 +511,8 @@ impl<'a, 'tcx> MutVisitor<'tcx> for RemoveStatements<'a, 'tcx> {
504
511
trace ! ( "removing statement {:?}" , stmt) ;
505
512
self . modified = true ;
506
513
507
- let mut visitor = StatementDeclMarker :: new ( self . used_locals . len ( ) , stmt) ;
514
+ let mut visitor = StatementDeclMarker :: new ( self . used_locals , stmt) ;
508
515
visitor. visit_statement ( stmt, Location { block, statement_index : i } ) ;
509
-
510
- for ( local, count) in visitor. used_locals . iter_enumerated ( ) {
511
- let used_count = & mut self . used_locals [ local] ;
512
-
513
- // If this is the local we're removing...
514
- if * used_count != 0 {
515
- * used_count -= count;
516
- }
517
- }
518
516
}
519
517
520
518
i += 1 ;
0 commit comments