@@ -546,6 +546,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
546546 }
547547 }
548548 }
549+
550+ fn should_const_prop ( & self ) -> bool {
551+ self . tcx . sess . opts . debugging_opts . mir_opt_level >= 2
552+ }
549553}
550554
551555fn type_size_of < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -639,7 +643,7 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
639643 assert ! ( self . places[ local] . is_none( ) ) ;
640644 self . places [ local] = Some ( value) ;
641645
642- if self . tcx . sess . opts . debugging_opts . mir_opt_level >= 2 {
646+ if self . should_const_prop ( ) {
643647 self . replace_with_const ( rval, value, statement. source_info . span ) ;
644648 }
645649 }
@@ -726,20 +730,25 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
726730 & msg,
727731 ) ;
728732 } else {
729- if let ScalarMaybeUndef :: Scalar ( scalar) = value_const {
730- * cond = self . operand_from_scalar (
731- scalar,
732- self . tcx . types . bool ,
733- source_info. span ,
734- ) ;
733+ if self . should_const_prop ( ) {
734+ if let ScalarMaybeUndef :: Scalar ( scalar) = value_const {
735+ * cond = self . operand_from_scalar (
736+ scalar,
737+ self . tcx . types . bool ,
738+ source_info. span ,
739+ ) ;
740+ }
735741 }
736742 }
737743 }
738744 } ,
739745 TerminatorKind :: SwitchInt { ref mut discr, switch_ty, .. } => {
740- if let Some ( value) = self . eval_operand ( & discr, source_info) {
741- if let ScalarMaybeUndef :: Scalar ( scalar) = self . ecx . read_scalar ( value) . unwrap ( ) {
742- * discr = self . operand_from_scalar ( scalar, switch_ty, source_info. span ) ;
746+ if self . should_const_prop ( ) {
747+ if let Some ( value) = self . eval_operand ( & discr, source_info) {
748+ if let ScalarMaybeUndef :: Scalar ( scalar) =
749+ self . ecx . read_scalar ( value) . unwrap ( ) {
750+ * discr = self . operand_from_scalar ( scalar, switch_ty, source_info. span ) ;
751+ }
743752 }
744753 }
745754 } ,
0 commit comments