@@ -765,6 +765,7 @@ impl<'tcx> Body<'tcx> {
765765        } ; 
766766
767767        // If this is a SwitchInt(const _), then we can just evaluate the constant and return. 
768+         // (The `SwitchConst` transform pass tries to ensure this.) 
768769        let  discr = match  discr { 
769770            Operand :: Constant ( constant)  => { 
770771                let  bits = eval_mono_const ( constant) ; 
@@ -773,24 +774,18 @@ impl<'tcx> Body<'tcx> {
773774            Operand :: Move ( place)  | Operand :: Copy ( place)  => place, 
774775        } ; 
775776
776-         // MIR for `if false` actually looks like this: 
777-         // _1 = const _ 
778-         // SwitchInt(_1) 
779-         // 
780777        // And MIR for if intrinsics::debug_assertions() looks like this: 
781778        // _1 = cfg!(debug_assertions) 
782779        // SwitchInt(_1) 
783780        // 
784781        // So we're going to try to recognize this pattern. 
785782        // 
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 UbChecks  to our 
785+         // discriminant place, we evaluate its value , as if we've 
786+         // const-propagated it  into the SwitchInt. 
790787
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 ( ) ?; 
794789
795790        let  ( place,  rvalue)  = last_stmt. kind . as_assign ( ) ?; 
796791
@@ -802,10 +797,6 @@ impl<'tcx> Body<'tcx> {
802797            Rvalue :: NullaryOp ( NullOp :: UbChecks ,  _)  => { 
803798                Some ( ( tcx. sess . opts . debug_assertions  as  u128 ,  targets) ) 
804799            } 
805-             Rvalue :: Use ( Operand :: Constant ( constant) )  => { 
806-                 let  bits = eval_mono_const ( constant) ; 
807-                 Some ( ( bits,  targets) ) 
808-             } 
809800            _ => None , 
810801        } 
811802    } 
0 commit comments