@@ -711,6 +711,7 @@ impl<'tcx> Body<'tcx> {
711
711
} ;
712
712
713
713
// If this is a SwitchInt(const _), then we can just evaluate the constant and return.
714
+ // (The `SwitchConst` transform pass tries to ensure this.)
714
715
let discr = match discr {
715
716
Operand :: Constant ( constant) => {
716
717
let bits = eval_mono_const ( constant) ?;
@@ -719,24 +720,18 @@ impl<'tcx> Body<'tcx> {
719
720
Operand :: Move ( place) | Operand :: Copy ( place) => place,
720
721
} ;
721
722
722
- // MIR for `if false` actually looks like this:
723
- // _1 = const _
724
- // SwitchInt(_1)
725
- //
726
723
// And MIR for if intrinsics::ub_checks() looks like this:
727
724
// _1 = UbChecks()
728
725
// SwitchInt(_1)
729
726
//
730
727
// So we're going to try to recognize this pattern.
731
728
//
732
- // If we have a SwitchInt on a non-const place, we find the most recent statement that
733
- // isn't a storage marker . If that statement is an assignment of a const to our
734
- // discriminant place, we evaluate and return the const , as if we've const-propagated it
735
- // into the SwitchInt.
729
+ // If we have a SwitchInt on a non-const place, we look at the last statement
730
+ // in the block . If that statement is an assignment of UbChecks to our
731
+ // discriminant place, we evaluate its value , as if we've
732
+ // const-propagated it into the SwitchInt.
736
733
737
- let last_stmt = block. statements . iter ( ) . rev ( ) . find ( |stmt| {
738
- !matches ! ( stmt. kind, StatementKind :: StorageDead ( _) | StatementKind :: StorageLive ( _) )
739
- } ) ?;
734
+ let last_stmt = block. statements . last ( ) ?;
740
735
741
736
let ( place, rvalue) = last_stmt. kind . as_assign ( ) ?;
742
737
@@ -746,10 +741,6 @@ impl<'tcx> Body<'tcx> {
746
741
747
742
match rvalue {
748
743
Rvalue :: NullaryOp ( NullOp :: UbChecks , _) => Some ( ( tcx. sess . ub_checks ( ) as u128 , targets) ) ,
749
- Rvalue :: Use ( Operand :: Constant ( constant) ) => {
750
- let bits = eval_mono_const ( constant) ?;
751
- Some ( ( bits, targets) )
752
- }
753
744
_ => None ,
754
745
}
755
746
}
0 commit comments