From: Santiago Pastorino Date: Wed, 1 May 2019 23:07:44 +0000 (+0200) Subject: Implement base_local iteratively X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=49f01413748f536f49b3d14845dbe5dd717b6b84;p=rust.git Implement base_local iteratively --- diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 0dc23f5ce47..f23ff47b5ff 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2055,10 +2055,13 @@ pub fn local(&self) -> Option { /// Finds the innermost `Local` from this `Place`. pub fn base_local(&self) -> Option { - 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), + } } }