Skip to content

Commit

Permalink
Rollup merge of rust-lang#55761 - ljedrz:fix_promote_candidate_hack, …
Browse files Browse the repository at this point in the history
…r=estebank

mir: remove a hacky recursive helper function

It can be replaced with a `while let` loop.
  • Loading branch information
kennytm authored Nov 8, 2018
2 parents 3d6df38 + 5159b32 commit eb5e607
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,11 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
match statement.kind {
StatementKind::Assign(_, box Rvalue::Ref(_, _, ref mut place)) => {
// Find the underlying local for this (necessarily interior) borrow.
// HACK(eddyb) using a recursive function because of mutable borrows.
fn interior_base<'a, 'tcx>(place: &'a mut Place<'tcx>)
-> &'a mut Place<'tcx> {
if let Place::Projection(ref mut proj) = *place {
assert_ne!(proj.elem, ProjectionElem::Deref);
return interior_base(&mut proj.base);
}
place
}
let place = interior_base(place);
let mut place = place;
while let Place::Projection(ref mut proj) = *place {
assert_ne!(proj.elem, ProjectionElem::Deref);
place = &mut proj.base;
};

let ty = place.ty(local_decls, self.tcx).to_ty(self.tcx);
let span = statement.source_info.span;
Expand Down

0 comments on commit eb5e607

Please sign in to comment.