@@ -775,6 +775,10 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
775775 // Projections are fine, because `&mut foo.x` will be caught by
776776 // `MutatingUseContext::Borrow` elsewhere.
777777 MutatingUse ( MutatingUseContext :: Projection )
778+ // These are just stores, where the storing is not propagatable, but there may be later
779+ // mutations of the same local via `Store`
780+ | MutatingUse ( MutatingUseContext :: Call )
781+ // Actual store that can possibly even propagate a value
778782 | MutatingUse ( MutatingUseContext :: Store ) => {
779783 if !self . found_assignment . insert ( local) {
780784 match & mut self . can_const_prop [ local] {
@@ -799,7 +803,21 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
799803 | NonMutatingUse ( NonMutatingUseContext :: Inspect )
800804 | NonMutatingUse ( NonMutatingUseContext :: Projection )
801805 | NonUse ( _) => { }
802- _ => {
806+
807+ // These could be propagated with a smarter analysis or just some careful thinking about
808+ // whether they'd be fine right now.
809+ MutatingUse ( MutatingUseContext :: AsmOutput )
810+ | MutatingUse ( MutatingUseContext :: Yield )
811+ | MutatingUse ( MutatingUseContext :: Drop )
812+ | MutatingUse ( MutatingUseContext :: Retag )
813+ // These can't ever be propagated under any scheme, as we can't reason about indirect
814+ // mutation.
815+ | NonMutatingUse ( NonMutatingUseContext :: SharedBorrow )
816+ | NonMutatingUse ( NonMutatingUseContext :: ShallowBorrow )
817+ | NonMutatingUse ( NonMutatingUseContext :: UniqueBorrow )
818+ | NonMutatingUse ( NonMutatingUseContext :: AddressOf )
819+ | MutatingUse ( MutatingUseContext :: Borrow )
820+ | MutatingUse ( MutatingUseContext :: AddressOf ) => {
803821 trace ! ( "local {:?} can't be propagaged because it's used: {:?}" , local, context) ;
804822 self . can_const_prop [ local] = ConstPropMode :: NoPropagation ;
805823 }
0 commit comments