Skip to content

Commit 4203f49

Browse files
committed
Prepare promote_consts MutVisitor to have projections interned
1 parent be71d2b commit 4203f49

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/librustc_mir/transform/promote_consts.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
191191
});
192192
}
193193

194+
fn is_temp_kind(&self, local: Local) -> bool {
195+
self.source.local_kind(local) == LocalKind::Temp
196+
}
197+
194198
/// Copies the initialization of this temp to the
195199
/// promoted MIR, recursing through temps.
196200
fn promote_temp(&mut self, temp: Local) -> Local {
@@ -396,10 +400,30 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
396400
local: &mut Local,
397401
_: PlaceContext,
398402
_: Location) {
399-
if self.source.local_kind(*local) == LocalKind::Temp {
403+
if self.is_temp_kind(*local) {
400404
*local = self.promote_temp(*local);
401405
}
402406
}
407+
408+
fn visit_place(
409+
&mut self,
410+
place: &mut Place<'tcx>,
411+
context: PlaceContext,
412+
location: Location,
413+
) {
414+
self.visit_place_base(&mut place.base, context, location);
415+
416+
let new_projection: Vec<_> = place.projection.iter().map(|elem|
417+
match elem {
418+
PlaceElem::Index(local) if self.is_temp_kind(*local) => {
419+
PlaceElem::Index(self.promote_temp(*local))
420+
}
421+
_ => elem.clone(),
422+
}
423+
).collect();
424+
425+
place.projection = new_projection.into_boxed_slice();
426+
}
403427
}
404428

405429
pub fn promote_candidates<'tcx>(

0 commit comments

Comments
 (0)