]> git.lizzy.rs Git - rust.git/commitdiff
Implement base_local iteratively
authorSantiago Pastorino <spastorino@gmail.com>
Wed, 1 May 2019 23:07:44 +0000 (01:07 +0200)
committerSantiago Pastorino <spastorino@gmail.com>
Thu, 2 May 2019 20:52:43 +0000 (22:52 +0200)
src/librustc/mir/mod.rs

index 0dc23f5ce47e58d1df1e58bbcd4bf3d38d77397d..f23ff47b5ff660635ef19b3ffd435986f5064f21 100644 (file)
@@ -2055,10 +2055,13 @@ pub fn local(&self) -> Option<Local> {
 
     /// 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),
+            }
         }
     }