@@ -1728,12 +1728,18 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
1728
1728
self . tcx
1729
1729
}
1730
1730
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 ) {
1732
1732
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) ;
1733
1738
}
1734
1739
1735
1740
fn visit_operand ( & mut self , operand : & mut Operand < ' tcx > , location : Location ) {
1736
1741
self . simplify_operand ( operand, location) ;
1742
+ self . super_operand ( operand, location) ;
1737
1743
}
1738
1744
1739
1745
fn visit_statement ( & mut self , stmt : & mut Statement < ' tcx > , location : Location ) {
@@ -1751,22 +1757,18 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
1751
1757
self . assign ( local, value) ;
1752
1758
Some ( value)
1753
1759
} else {
1754
- // Non-local assignments maybe invalidate deref.
1755
- self . invalidate_derefs ( ) ;
1756
1760
value
1757
1761
} ;
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
+ }
1767
1771
}
1768
-
1769
- return ;
1770
1772
}
1771
1773
self . super_statement ( stmt, location) ;
1772
1774
}
0 commit comments