@@ -187,6 +187,14 @@ impl<'tcx> Mir<'tcx> {
187187 self . var_decls . len ( ) +
188188 self . temp_decls . len ( ) + 1
189189 }
190+
191+ /// Changes a statement to a nop. This is both faster than deleting instructions and avoids
192+ /// invalidating statement indices in `Location`s.
193+ pub fn make_statement_nop ( & mut self , location : Location ) {
194+ let block = & mut self [ location. block ] ;
195+ debug_assert ! ( location. statement_index < block. statements. len( ) ) ;
196+ block. statements [ location. statement_index ] . make_nop ( )
197+ }
190198}
191199
192200impl < ' tcx > Index < BasicBlock > for Mir < ' tcx > {
@@ -686,6 +694,14 @@ pub struct Statement<'tcx> {
686694 pub kind : StatementKind < ' tcx > ,
687695}
688696
697+ impl < ' tcx > Statement < ' tcx > {
698+ /// Changes a statement to a nop. This is both faster than deleting instructions and avoids
699+ /// invalidating statement indices in `Location`s.
700+ pub fn make_nop ( & mut self ) {
701+ self . kind = StatementKind :: Nop
702+ }
703+ }
704+
689705#[ derive( Clone , Debug , RustcEncodable , RustcDecodable ) ]
690706pub enum StatementKind < ' tcx > {
691707 /// Write the RHS Rvalue to the LHS Lvalue.
@@ -699,6 +715,9 @@ pub enum StatementKind<'tcx> {
699715
700716 /// End the current live range for the storage of the local.
701717 StorageDead ( Lvalue < ' tcx > ) ,
718+
719+ /// No-op. Useful for deleting instructions without affecting statement indices.
720+ Nop ,
702721}
703722
704723impl < ' tcx > Debug for Statement < ' tcx > {
@@ -711,6 +730,7 @@ impl<'tcx> Debug for Statement<'tcx> {
711730 SetDiscriminant { lvalue : ref lv, variant_index : index} => {
712731 write ! ( fmt, "discriminant({:?}) = {:?}" , lv, index)
713732 }
733+ Nop => write ! ( fmt, "nop" ) ,
714734 }
715735 }
716736}
0 commit comments