@@ -539,6 +539,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
539
539
}
540
540
}
541
541
}
542
+
543
+ fn should_const_prop ( & self ) -> bool {
544
+ self . tcx . sess . opts . debugging_opts . mir_opt_level >= 2
545
+ }
542
546
}
543
547
544
548
fn type_size_of < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -632,7 +636,7 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
632
636
assert ! ( self . places[ local] . is_none( ) ) ;
633
637
self . places [ local] = Some ( value) ;
634
638
635
- if self . tcx . sess . opts . debugging_opts . mir_opt_level >= 2 {
639
+ if self . should_const_prop ( ) {
636
640
self . replace_with_const ( rval, value) ;
637
641
}
638
642
}
@@ -719,16 +723,20 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
719
723
& msg,
720
724
) ;
721
725
} else {
722
- if let ScalarMaybeUndef :: Scalar ( scalar) = value_const {
723
- * cond = self . operand_from_scalar ( scalar, self . tcx . types . bool ) ;
726
+ if self . should_const_prop ( ) {
727
+ if let ScalarMaybeUndef :: Scalar ( scalar) = value_const {
728
+ * cond = self . operand_from_scalar ( scalar, self . tcx . types . bool ) ;
729
+ }
724
730
}
725
731
}
726
732
}
727
733
} ,
728
734
TerminatorKind :: SwitchInt { ref mut discr, switch_ty, .. } => {
729
- if let Some ( value) = self . eval_operand ( & discr, source_info) {
730
- if let ScalarMaybeUndef :: Scalar ( scalar) = self . ecx . read_scalar ( value) . unwrap ( ) {
731
- * discr = self . operand_from_scalar ( scalar, switch_ty) ;
735
+ if self . should_const_prop ( ) {
736
+ if let Some ( value) = self . eval_operand ( & discr, source_info) {
737
+ if let Ok ( ScalarMaybeUndef :: Scalar ( scalar) ) = self . ecx . read_scalar ( value) {
738
+ * discr = self . operand_from_scalar ( scalar, switch_ty) ;
739
+ }
732
740
}
733
741
}
734
742
} ,
0 commit comments