@@ -765,6 +765,7 @@ impl<'tcx> Body<'tcx> {
765
765
} ;
766
766
767
767
// If this is a SwitchInt(const _), then we can just evaluate the constant and return.
768
+ // (The `SwitchConst` transform pass tries to ensure this.)
768
769
let discr = match discr {
769
770
Operand :: Constant ( constant) => {
770
771
let bits = eval_mono_const ( constant) ;
@@ -773,24 +774,18 @@ impl<'tcx> Body<'tcx> {
773
774
Operand :: Move ( place) | Operand :: Copy ( place) => place,
774
775
} ;
775
776
776
- // MIR for `if false` actually looks like this:
777
- // _1 = const _
778
- // SwitchInt(_1)
779
- //
780
777
// And MIR for if intrinsics::debug_assertions() looks like this:
781
778
// _1 = cfg!(debug_assertions)
782
779
// SwitchInt(_1)
783
780
//
784
781
// So we're going to try to recognize this pattern.
785
782
//
786
- // If we have a SwitchInt on a non-const place, we find the most recent statement that
787
- // isn't a storage marker. If that statement is an assignment of a const to our
788
- // discriminant place, we evaluate and return the const, as if we've const-propagated it
789
- // into the SwitchInt.
783
+ // If we have a SwitchInt on a non-const place, we look at the last statement
784
+ // in the block. If that statement is an assignment of a const to our
785
+ // discriminant place, we evaluate and return the const, as if we've
786
+ // const-propagated it into the SwitchInt.
790
787
791
- let last_stmt = block. statements . iter ( ) . rev ( ) . find ( |stmt| {
792
- !matches ! ( stmt. kind, StatementKind :: StorageDead ( _) | StatementKind :: StorageLive ( _) )
793
- } ) ?;
788
+ let last_stmt = block. statements . last ( ) ?;
794
789
795
790
let ( place, rvalue) = last_stmt. kind . as_assign ( ) ?;
796
791
@@ -802,10 +797,6 @@ impl<'tcx> Body<'tcx> {
802
797
Rvalue :: NullaryOp ( NullOp :: UbChecks , _) => {
803
798
Some ( ( tcx. sess . opts . debug_assertions as u128 , targets) )
804
799
}
805
- Rvalue :: Use ( Operand :: Constant ( constant) ) => {
806
- let bits = eval_mono_const ( constant) ;
807
- Some ( ( bits, targets) )
808
- }
809
800
_ => None ,
810
801
}
811
802
}
0 commit comments