@@ -546,6 +546,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
546
546
}
547
547
}
548
548
}
549
+
550
+ fn should_const_prop ( & self ) -> bool {
551
+ self . tcx . sess . opts . debugging_opts . mir_opt_level >= 2
552
+ }
549
553
}
550
554
551
555
fn 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> {
639
643
assert ! ( self . places[ local] . is_none( ) ) ;
640
644
self . places [ local] = Some ( value) ;
641
645
642
- if self . tcx . sess . opts . debugging_opts . mir_opt_level >= 2 {
646
+ if self . should_const_prop ( ) {
643
647
self . replace_with_const ( rval, value, statement. source_info . span ) ;
644
648
}
645
649
}
@@ -726,20 +730,25 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
726
730
& msg,
727
731
) ;
728
732
} 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
+ }
735
741
}
736
742
}
737
743
}
738
744
} ,
739
745
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
+ }
743
752
}
744
753
}
745
754
} ,
0 commit comments