1
Fork 0

Rollup merge of #107662 - cjgillot:copy-projection, r=oli-obk

Turn projections into copies in CopyProp.

The current implementation can leave behind projections that are moved out several times.

This PR widens the check to turn such moves into copies: a move out of a projection of a copy is equivalent to a copy of the original projection.
This commit is contained in:
Matthias Krüger 2023-02-07 17:57:15 +01:00 committed by GitHub
commit 306dbaf574
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 3 deletions

View file

@ -153,8 +153,9 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
fn visit_operand(&mut self, operand: &mut Operand<'tcx>, loc: Location) {
if let Operand::Move(place) = *operand
&& let Some(local) = place.as_local()
&& !self.fully_moved.contains(local)
// A move out of a projection of a copy is equivalent to a copy of the original projection.
&& !place.has_deref()
&& !self.fully_moved.contains(place.local)
{
*operand = Operand::Copy(place);
}