Skip to content

Commit 4fec5ef

Browse files
committed
rustc_mir: promote borrows' underlying temps, and project at runtime.
1 parent d79dee0 commit 4fec5ef

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/librustc_mir/transform/promote_consts.rs

+12
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
309309
let ref mut statement = blocks[loc.block].statements[loc.statement_index];
310310
match statement.kind {
311311
StatementKind::Assign(_, Rvalue::Ref(r, bk, ref mut place)) => {
312+
// Find the underlying local for this (necessarilly interior) borrow.
313+
// HACK(eddyb) using a recursive function because of mutable borrows.
314+
fn interior_base<'a, 'tcx>(place: &'a mut Place<'tcx>)
315+
-> &'a mut Place<'tcx> {
316+
if let Place::Projection(ref mut proj) = *place {
317+
assert_ne!(proj.elem, ProjectionElem::Deref);
318+
return interior_base(&mut proj.base);
319+
}
320+
place
321+
}
322+
let place = interior_base(place);
323+
312324
let ty = place.ty(local_decls, self.tcx).to_ty(self.tcx);
313325
let ref_ty = self.tcx.mk_ref(r,
314326
ty::TypeAndMut {

0 commit comments

Comments
 (0)