@@ -756,7 +756,13 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
756756 && let Some ( v) = self . simplify_place_value ( & mut pointee, location)
757757 {
758758 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+ }
760766 }
761767 if let Some ( local) = self . try_as_local ( value, location) {
762768 // Both `local` and `Place { local: place.local, projection: projection[..index] }`
@@ -774,7 +780,12 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
774780 && let Some ( v) = self . simplify_place_value ( & mut pointee, location)
775781 {
776782 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+ }
778789 }
779790 if let Some ( new_local) = self . try_as_local ( value, location) {
780791 place_ref = PlaceRef { local : new_local, projection : & [ ] } ;
0 commit comments