diff options
| author | bors <bors@rust-lang.org> | 2023-05-05 04:48:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-05-05 04:48:50 +0000 |
| commit | 3320f2fab64f36dae94b830f8c4b166857b6919b (patch) | |
| tree | ed35a767748983cfed5de4965d86393c393a9656 /compiler/rustc_mir_transform/src | |
| parent | 74c4821045c68d42bb8b8a7c998bdb5c2a72bd0d (diff) | |
| parent | 650dc01a644c0429cd4853749f9077ce353b29e6 (diff) | |
| download | rust-3320f2fab64f36dae94b830f8c4b166857b6919b.tar.gz rust-3320f2fab64f36dae94b830f8c4b166857b6919b.zip | |
Auto merge of #111231 - JohnTitor:rollup-a25ff8v, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #110946 (avoid duplicating TLS state between test std and realstd) - #110954 (Reject borrows of projections in ConstProp.) - #111052 (Fix problems with backtraces in two ui tests.) - #111132 (cleanup nll generalizer) - #111173 (Still more encoder cleanups) - #111187 (bootstrap: add llvm-project/runtimes to the sources) - #111213 (Fixup "since" dates for `array_tuple_conv` feature) - #111223 (Use `free-args` consistently in bootstrap) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/const_prop.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index b3a3a25ebe8..7f995c69a48 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -714,13 +714,22 @@ impl CanConstProp { } } -impl Visitor<'_> for CanConstProp { +impl<'tcx> Visitor<'tcx> for CanConstProp { + fn visit_place(&mut self, place: &Place<'tcx>, mut context: PlaceContext, loc: Location) { + use rustc_middle::mir::visit::PlaceContext::*; + + // Dereferencing just read the addess of `place.local`. + if place.projection.first() == Some(&PlaceElem::Deref) { + context = NonMutatingUse(NonMutatingUseContext::Copy); + } + + self.visit_local(place.local, context, loc); + self.visit_projection(place.as_ref(), context, loc); + } + fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) { use rustc_middle::mir::visit::PlaceContext::*; match context { - // Projections are fine, because `&mut foo.x` will be caught by - // `MutatingUseContext::Borrow` elsewhere. - MutatingUse(MutatingUseContext::Projection) // These are just stores, where the storing is not propagatable, but there may be later // mutations of the same local via `Store` | MutatingUse(MutatingUseContext::Call) @@ -751,7 +760,6 @@ impl Visitor<'_> for CanConstProp { NonMutatingUse(NonMutatingUseContext::Copy) | NonMutatingUse(NonMutatingUseContext::Move) | NonMutatingUse(NonMutatingUseContext::Inspect) - | NonMutatingUse(NonMutatingUseContext::Projection) | NonMutatingUse(NonMutatingUseContext::PlaceMention) | NonUse(_) => {} @@ -771,6 +779,8 @@ impl Visitor<'_> for CanConstProp { trace!("local {:?} can't be propagated because it's used: {:?}", local, context); self.can_const_prop[local] = ConstPropMode::NoPropagation; } + MutatingUse(MutatingUseContext::Projection) + | NonMutatingUse(NonMutatingUseContext::Projection) => bug!("visit_place should not pass {context:?} for {local:?}"), } } } |
