@@ -1728,12 +1728,18 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
17281728 self . tcx
17291729 }
17301730
1731- fn visit_place ( & mut self , place : & mut Place < ' tcx > , _ : PlaceContext , location : Location ) {
1731+ fn visit_place ( & mut self , place : & mut Place < ' tcx > , context : PlaceContext , location : Location ) {
17321732 self . simplify_place_projection ( place, location) ;
1733+ if context. is_mutating_use ( ) && !place. projection . is_empty ( ) {
1734+ // Non-local mutation maybe invalidate deref.
1735+ self . invalidate_derefs ( ) ;
1736+ }
1737+ self . super_place ( place, context, location) ;
17331738 }
17341739
17351740 fn visit_operand ( & mut self , operand : & mut Operand < ' tcx > , location : Location ) {
17361741 self . simplify_operand ( operand, location) ;
1742+ self . super_operand ( operand, location) ;
17371743 }
17381744
17391745 fn visit_statement ( & mut self , stmt : & mut Statement < ' tcx > , location : Location ) {
@@ -1751,22 +1757,18 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
17511757 self . assign ( local, value) ;
17521758 Some ( value)
17531759 } else {
1754- // Non-local assignments maybe invalidate deref.
1755- self . invalidate_derefs ( ) ;
17561760 value
17571761 } ;
1758- let Some ( value) = value else { return } ;
1759-
1760- if let Some ( const_ ) = self . try_as_constant ( value ) {
1761- * rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( const_ ) ) ) ;
1762- } else if let Some ( local ) = self . try_as_local ( value , location )
1763- && * rvalue != Rvalue :: Use ( Operand :: Move ( local . into ( ) ) )
1764- {
1765- * rvalue = Rvalue :: Use ( Operand :: Copy ( local . into ( ) ) ) ;
1766- self . reused_locals . insert ( local ) ;
1762+ if let Some ( value) = value {
1763+ if let Some ( const_ ) = self . try_as_constant ( value ) {
1764+ * rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( const_ ) ) ) ;
1765+ } else if let Some ( local ) = self . try_as_local ( value , location )
1766+ && * rvalue != Rvalue :: Use ( Operand :: Move ( local . into ( ) ) )
1767+ {
1768+ * rvalue = Rvalue :: Use ( Operand :: Copy ( local . into ( ) ) ) ;
1769+ self . reused_locals . insert ( local ) ;
1770+ }
17671771 }
1768-
1769- return ;
17701772 }
17711773 self . super_statement ( stmt, location) ;
17721774 }
0 commit comments