From 49f01413748f536f49b3d14845dbe5dd717b6b84 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 2 May 2019 01:07:44 +0200 Subject: [PATCH] Implement base_local iteratively --- src/librustc/mir/mod.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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), + } } } -- 2.44.0