@@ -718,8 +718,6 @@ pub enum ConstPropMode {
718718 FullConstProp ,
719719 /// The `Local` can only be propagated into and from its own block.
720720 OnlyInsideOwnBlock ,
721- /// The `Local` can be propagated into but reads cannot be propagated.
722- OnlyPropagateInto ,
723721 /// The `Local` cannot be part of propagation at all. Any statement
724722 /// referencing it either for reading or writing will not get propagated.
725723 NoPropagation ,
@@ -729,8 +727,6 @@ pub struct CanConstProp {
729727 can_const_prop : IndexVec < Local , ConstPropMode > ,
730728 // False at the beginning. Once set, no more assignments are allowed to that local.
731729 found_assignment : BitSet < Local > ,
732- // Cache of locals' information
733- local_kinds : IndexVec < Local , LocalKind > ,
734730}
735731
736732impl CanConstProp {
@@ -743,10 +739,6 @@ impl CanConstProp {
743739 let mut cpv = CanConstProp {
744740 can_const_prop : IndexVec :: from_elem ( ConstPropMode :: FullConstProp , & body. local_decls ) ,
745741 found_assignment : BitSet :: new_empty ( body. local_decls . len ( ) ) ,
746- local_kinds : IndexVec :: from_fn_n (
747- |local| body. local_kind ( local) ,
748- body. local_decls . len ( ) ,
749- ) ,
750742 } ;
751743 for ( local, val) in cpv. can_const_prop . iter_enumerated_mut ( ) {
752744 let ty = body. local_decls [ local] . ty ;
@@ -759,24 +751,10 @@ impl CanConstProp {
759751 continue ;
760752 }
761753 }
762- // Cannot use args at all
763- // Cannot use locals because if x < y { y - x } else { x - y } would
764- // lint for x != y
765- // FIXME(oli-obk): lint variables until they are used in a condition
766- // FIXME(oli-obk): lint if return value is constant
767- if cpv. local_kinds [ local] == LocalKind :: Arg {
768- * val = ConstPropMode :: OnlyPropagateInto ;
769- trace ! (
770- "local {:?} can't be const propagated because it's a function argument" ,
771- local
772- ) ;
773- } else if cpv. local_kinds [ local] == LocalKind :: Var {
774- * val = ConstPropMode :: OnlyInsideOwnBlock ;
775- trace ! (
776- "local {:?} will only be propagated inside its block, because it's a user variable" ,
777- local
778- ) ;
779- }
754+ }
755+ // Consider that arguments are assigned on entry.
756+ for arg in body. args_iter ( ) {
757+ cpv. found_assignment . insert ( arg) ;
780758 }
781759 cpv. visit_body ( & body) ;
782760 cpv. can_const_prop
@@ -806,7 +784,6 @@ impl Visitor<'_> for CanConstProp {
806784 // states as applicable.
807785 ConstPropMode :: OnlyInsideOwnBlock => { }
808786 ConstPropMode :: NoPropagation => { }
809- ConstPropMode :: OnlyPropagateInto => { }
810787 other @ ConstPropMode :: FullConstProp => {
811788 trace ! (
812789 "local {:?} can't be propagated because of multiple assignments. Previous state: {:?}" ,
@@ -897,7 +874,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
897874 place. local
898875 ) ;
899876 }
900- ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
877+ ConstPropMode :: NoPropagation => {
901878 trace ! ( "can't propagate into {:?}" , place) ;
902879 if place. local != RETURN_PLACE {
903880 Self :: remove_const ( & mut self . ecx , place. local ) ;
@@ -933,7 +910,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
933910 Self :: remove_const ( & mut self . ecx , place. local ) ;
934911 }
935912 }
936- ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
913+ ConstPropMode :: NoPropagation => {
937914 Self :: remove_const ( & mut self . ecx , place. local ) ;
938915 }
939916 }
0 commit comments