diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-02-07 17:57:15 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-07 17:57:15 +0100 |
| commit | 306dbaf5741a4d76cb2ba0c5feca24414cd1c51a (patch) | |
| tree | 973f07147ec1cb78d44affe7e98cba80604550eb /compiler/rustc_mir_transform/src | |
| parent | 917662a8f6f4ddce6993ed7a528f1d8d8dd2764d (diff) | |
| parent | 9c5add14e7c1695bc018a941c383f01a7dde8730 (diff) | |
| download | rust-306dbaf5741a4d76cb2ba0c5feca24414cd1c51a.tar.gz rust-306dbaf5741a4d76cb2ba0c5feca24414cd1c51a.zip | |
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.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/copy_prop.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/compiler/rustc_mir_transform/src/copy_prop.rs b/compiler/rustc_mir_transform/src/copy_prop.rs index 4c7d45be075..6e279232bcb 100644 --- a/compiler/rustc_mir_transform/src/copy_prop.rs +++ b/compiler/rustc_mir_transform/src/copy_prop.rs @@ -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); } |
