@@ -637,6 +637,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
637637 if place. is_indirect ( )
638638 && let Some ( base) = self . locals [ place. local ]
639639 && let Some ( new_local) = self . try_as_local ( base, location)
640+ && place. local != new_local
640641 {
641642 place. local = new_local;
642643 self . reused_locals . insert ( new_local) ;
@@ -646,18 +647,20 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
646647
647648 for i in 0 ..projection. len ( ) {
648649 let elem = projection[ i] ;
649- if let ProjectionElem :: Index ( idx ) = elem
650- && let Some ( idx) = self . locals [ idx ]
650+ if let ProjectionElem :: Index ( idx_local ) = elem
651+ && let Some ( idx) = self . locals [ idx_local ]
651652 {
652653 if let Some ( offset) = self . evaluated [ idx] . as_ref ( )
653654 && let Ok ( offset) = self . ecx . read_target_usize ( offset)
654655 && let Some ( min_length) = offset. checked_add ( 1 )
655656 {
656657 projection. to_mut ( ) [ i] =
657658 ProjectionElem :: ConstantIndex { offset, min_length, from_end : false } ;
658- } else if let Some ( new_idx) = self . try_as_local ( idx, location) {
659- projection. to_mut ( ) [ i] = ProjectionElem :: Index ( new_idx) ;
660- self . reused_locals . insert ( new_idx) ;
659+ } else if let Some ( new_idx_local) = self . try_as_local ( idx, location)
660+ && idx_local != new_idx_local
661+ {
662+ projection. to_mut ( ) [ i] = ProjectionElem :: Index ( new_idx_local) ;
663+ self . reused_locals . insert ( new_idx_local) ;
661664 }
662665 }
663666 }
0 commit comments