@@ -756,7 +756,13 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
756
756
&& let Some ( v) = self . simplify_place_value ( & mut pointee, location)
757
757
{
758
758
value = v;
759
- place_ref = pointee. project_deeper ( & place. projection [ index..] , self . tcx ) . as_ref ( ) ;
759
+ // `pointee` holds a `Place`, so `ProjectionElem::Index` holds a `Local`.
760
+ // That local is SSA, but we otherwise have no guarantee on that local's value at
761
+ // the current location compared to its value where `pointee` was borrowed.
762
+ if pointee. projection . iter ( ) . all ( |elem| !matches ! ( elem, ProjectionElem :: Index ( _) ) ) {
763
+ place_ref =
764
+ pointee. project_deeper ( & place. projection [ index..] , self . tcx ) . as_ref ( ) ;
765
+ }
760
766
}
761
767
if let Some ( local) = self . try_as_local ( value, location) {
762
768
// Both `local` and `Place { local: place.local, projection: projection[..index] }`
@@ -774,7 +780,12 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
774
780
&& let Some ( v) = self . simplify_place_value ( & mut pointee, location)
775
781
{
776
782
value = v;
777
- place_ref = pointee. project_deeper ( & [ ] , self . tcx ) . as_ref ( ) ;
783
+ // `pointee` holds a `Place`, so `ProjectionElem::Index` holds a `Local`.
784
+ // That local is SSA, but we otherwise have no guarantee on that local's value at
785
+ // the current location compared to its value where `pointee` was borrowed.
786
+ if pointee. projection . iter ( ) . all ( |elem| !matches ! ( elem, ProjectionElem :: Index ( _) ) ) {
787
+ place_ref = pointee. project_deeper ( & [ ] , self . tcx ) . as_ref ( ) ;
788
+ }
778
789
}
779
790
if let Some ( new_local) = self . try_as_local ( value, location) {
780
791
place_ref = PlaceRef { local : new_local, projection : & [ ] } ;
0 commit comments