@@ -187,6 +187,14 @@ impl<'tcx> Mir<'tcx> {
187
187
self . var_decls . len ( ) +
188
188
self . temp_decls . len ( ) + 1
189
189
}
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
+ }
190
198
}
191
199
192
200
impl < ' tcx > Index < BasicBlock > for Mir < ' tcx > {
@@ -686,6 +694,14 @@ pub struct Statement<'tcx> {
686
694
pub kind : StatementKind < ' tcx > ,
687
695
}
688
696
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
+
689
705
#[ derive( Clone , Debug , RustcEncodable , RustcDecodable ) ]
690
706
pub enum StatementKind < ' tcx > {
691
707
/// Write the RHS Rvalue to the LHS Lvalue.
@@ -699,6 +715,9 @@ pub enum StatementKind<'tcx> {
699
715
700
716
/// End the current live range for the storage of the local.
701
717
StorageDead ( Lvalue < ' tcx > ) ,
718
+
719
+ /// No-op. Useful for deleting instructions without affecting statement indices.
720
+ Nop ,
702
721
}
703
722
704
723
impl < ' tcx > Debug for Statement < ' tcx > {
@@ -711,6 +730,7 @@ impl<'tcx> Debug for Statement<'tcx> {
711
730
SetDiscriminant { lvalue : ref lv, variant_index : index} => {
712
731
write ! ( fmt, "discriminant({:?}) = {:?}" , lv, index)
713
732
}
733
+ Nop => write ! ( fmt, "nop" ) ,
714
734
}
715
735
}
716
736
}
0 commit comments