@@ -438,13 +438,16 @@ impl<'a, 'tcx> Visitor<'tcx> for DeclMarker<'a, 'tcx> {
438438}
439439
440440struct StatementDeclMarker < ' a , ' tcx > {
441- used_locals : IndexVec < Local , usize > ,
441+ used_locals : & ' a mut IndexVec < Local , usize > ,
442442 statement : & ' a Statement < ' tcx > ,
443443}
444444
445445impl < ' 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 }
448451 }
449452}
450453
@@ -457,7 +460,11 @@ impl<'a, 'tcx> Visitor<'tcx> for StatementDeclMarker<'a, 'tcx> {
457460 }
458461 }
459462
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+ }
461468 }
462469}
463470
@@ -504,17 +511,8 @@ impl<'a, 'tcx> MutVisitor<'tcx> for RemoveStatements<'a, 'tcx> {
504511 trace ! ( "removing statement {:?}" , stmt) ;
505512 self . modified = true ;
506513
507- let mut visitor = StatementDeclMarker :: new ( self . used_locals . len ( ) , stmt) ;
514+ let mut visitor = StatementDeclMarker :: new ( self . used_locals , stmt) ;
508515 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- }
518516 }
519517
520518 i += 1 ;
0 commit comments