@@ -721,8 +721,6 @@ enum ConstPropMode {
721
721
OnlyInsideOwnBlock ,
722
722
/// The `Local` can be propagated into but reads cannot be propagated.
723
723
OnlyPropagateInto ,
724
- /// No propagation is allowed at all.
725
- NoPropagation ,
726
724
}
727
725
728
726
struct CanConstProp {
@@ -793,7 +791,7 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
793
791
"local {:?} can't be propagated because of multiple assignments" ,
794
792
local,
795
793
) ;
796
- * other = ConstPropMode :: NoPropagation ;
794
+ * other = ConstPropMode :: OnlyPropagateInto ;
797
795
}
798
796
}
799
797
}
@@ -820,7 +818,7 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
820
818
| MutatingUse ( MutatingUseContext :: Borrow )
821
819
| MutatingUse ( MutatingUseContext :: AddressOf ) => {
822
820
trace ! ( "local {:?} can't be propagaged because it's used: {:?}" , local, context) ;
823
- self . can_const_prop [ local] = ConstPropMode :: NoPropagation ;
821
+ self . can_const_prop [ local] = ConstPropMode :: OnlyPropagateInto ;
824
822
}
825
823
}
826
824
}
@@ -852,31 +850,28 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
852
850
if let Ok ( place_layout) = self . tcx . layout_of ( self . param_env . and ( place_ty) ) {
853
851
let can_const_prop = self . can_const_prop [ place. local ] ;
854
852
if let Some ( ( ) ) = self . const_prop ( rval, place_layout, source_info, place) {
855
- if can_const_prop != ConstPropMode :: NoPropagation {
856
- // This will return None for variables that are from other blocks,
857
- // so it should be okay to propagate from here on down.
858
- if let Some ( value) = self . get_const ( place) {
859
- if self . should_const_prop ( value) {
860
- trace ! ( "replacing {:?} with {:?}" , rval, value) ;
861
- self . replace_with_const ( rval, value, source_info) ;
862
- if can_const_prop == ConstPropMode :: FullConstProp
863
- || can_const_prop == ConstPropMode :: OnlyInsideOwnBlock
864
- {
865
- trace ! ( "propagated into {:?}" , place) ;
866
- }
867
- }
868
- if can_const_prop == ConstPropMode :: OnlyInsideOwnBlock {
869
- trace ! (
870
- "found local restricted to its block. Will remove it from const-prop after block is finished. Local: {:?}" ,
871
- place. local
872
- ) ;
873
- self . locals_of_current_block . insert ( place. local ) ;
853
+ // This will return None for variables that are from other blocks,
854
+ // so it should be okay to propagate from here on down.
855
+ if let Some ( value) = self . get_const ( place) {
856
+ if self . should_const_prop ( value) {
857
+ trace ! ( "replacing {:?} with {:?}" , rval, value) ;
858
+ self . replace_with_const ( rval, value, source_info) ;
859
+ if can_const_prop == ConstPropMode :: FullConstProp
860
+ || can_const_prop == ConstPropMode :: OnlyInsideOwnBlock
861
+ {
862
+ trace ! ( "propagated into {:?}" , place) ;
874
863
}
875
864
}
876
865
}
877
- if can_const_prop == ConstPropMode :: OnlyPropagateInto
878
- || can_const_prop == ConstPropMode :: NoPropagation
879
- {
866
+ if can_const_prop == ConstPropMode :: OnlyInsideOwnBlock {
867
+ trace ! (
868
+ "found local restricted to its block. Will remove it from const-prop after block is finished. Local: {:?}" ,
869
+ place. local
870
+ ) ;
871
+ self . locals_of_current_block . insert ( place. local ) ;
872
+ }
873
+
874
+ if can_const_prop == ConstPropMode :: OnlyPropagateInto {
880
875
trace ! ( "can't propagate into {:?}" , place) ;
881
876
if place. local != RETURN_PLACE {
882
877
Self :: remove_const ( & mut self . ecx , place. local ) ;
0 commit comments