Skip to content

mir: Do not modify NonUse in super_projection_elem #144998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,18 +1205,19 @@ macro_rules! visit_place_fns {
self.super_projection_elem(place_ref, elem, context, location);
}

fn super_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
let mut context = context;

if !place.projection.is_empty() {
if context.is_use() {
// ^ Only change the context if it is a real use, not a "use" in debuginfo.
context = if context.is_mutating_use() {
PlaceContext::MutatingUse(MutatingUseContext::Projection)
} else {
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
};
}
fn super_place(
&mut self,
place: &Place<'tcx>,
mut context: PlaceContext,
location: Location,
) {
if !place.projection.is_empty() && context.is_use() {
// ^ Only change the context if it is a real use, not a "use" in debuginfo.
context = if context.is_mutating_use() {
PlaceContext::MutatingUse(MutatingUseContext::Projection)
} else {
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
};
}

self.visit_local(place.local, context, location);
Expand All @@ -1239,7 +1240,7 @@ macro_rules! visit_place_fns {
&mut self,
_place_ref: PlaceRef<'tcx>,
elem: PlaceElem<'tcx>,
_context: PlaceContext,
context: PlaceContext,
location: Location,
) {
match elem {
Expand All @@ -1252,7 +1253,12 @@ macro_rules! visit_place_fns {
ProjectionElem::Index(local) => {
self.visit_local(
local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
if context.is_use() {
// ^ Only change the context if it is a real use, not a "use" in debuginfo.
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy)
} else {
context
},
location,
);
}
Expand Down
Loading