Skip to content

Commit c152aa8

Browse files
Rollup merge of #144998 - dianqk:visit-no-use-proj, r=cjgillot
mir: Do not modify NonUse in `super_projection_elem` Split from #142771. r? cjgillot
2 parents e56c241 + d55cc9a commit c152aa8

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,18 +1205,19 @@ macro_rules! visit_place_fns {
12051205
self.super_projection_elem(place_ref, elem, context, ___location);
12061206
}
12071207

1208-
fn super_place(&mut self, place: &Place<'tcx>, context: PlaceContext, ___location: Location) {
1209-
let mut context = context;
1210-
1211-
if !place.projection.is_empty() {
1212-
if context.is_use() {
1213-
// ^ Only change the context if it is a real use, not a "use" in debuginfo.
1214-
context = if context.is_mutating_use() {
1215-
PlaceContext::MutatingUse(MutatingUseContext::Projection)
1216-
} else {
1217-
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
1218-
};
1219-
}
1208+
fn super_place(
1209+
&mut self,
1210+
place: &Place<'tcx>,
1211+
mut context: PlaceContext,
1212+
___location: Location,
1213+
) {
1214+
if !place.projection.is_empty() && context.is_use() {
1215+
// ^ Only change the context if it is a real use, not a "use" in debuginfo.
1216+
context = if context.is_mutating_use() {
1217+
PlaceContext::MutatingUse(MutatingUseContext::Projection)
1218+
} else {
1219+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
1220+
};
12201221
}
12211222

12221223
self.visit_local(place.local, context, ___location);
@@ -1239,7 +1240,7 @@ macro_rules! visit_place_fns {
12391240
&mut self,
12401241
_place_ref: PlaceRef<'tcx>,
12411242
elem: PlaceElem<'tcx>,
1242-
_context: PlaceContext,
1243+
context: PlaceContext,
12431244
___location: Location,
12441245
) {
12451246
match elem {
@@ -1252,7 +1253,12 @@ macro_rules! visit_place_fns {
12521253
ProjectionElem::Index(local) => {
12531254
self.visit_local(
12541255
local,
1255-
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
1256+
if context.is_use() {
1257+
// ^ Only change the context if it is a real use, not a "use" in debuginfo.
1258+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy)
1259+
} else {
1260+
context
1261+
},
12561262
___location,
12571263
);
12581264
}

0 commit comments

Comments
 (0)