Implement base_local iteratively

This commit is contained in:
Santiago Pastorino 2019-05-02 01:07:44 +02:00
parent 9f7b953a7e
commit 49f0141374

View File

@ -2055,10 +2055,13 @@ impl<'tcx> Place<'tcx> {
/// Finds the innermost `Local` from this `Place`.
pub fn base_local(&self) -> Option<Local> {
match self {
Place::Base(PlaceBase::Local(local)) => Some(*local),
Place::Projection(box Projection { base, elem: _ }) => base.base_local(),
Place::Base(PlaceBase::Static(..)) => None,
let mut place = self;
loop {
match place {
Place::Projection(proj) => place = &proj.base,
Place::Base(PlaceBase::Static(_)) => return None,
Place::Base(PlaceBase::Local(local)) => return Some(*local),
}
}
}