diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2019-05-02 01:07:44 +0200 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2019-05-02 22:52:43 +0200 |
| commit | 49f01413748f536f49b3d14845dbe5dd717b6b84 (patch) | |
| tree | d489b0e7eb6dba88270c07608c3023b95d7747b2 | |
| parent | 9f7b953a7e691139ada3f390cd6f8ee9e5279642 (diff) | |
| download | rust-49f01413748f536f49b3d14845dbe5dd717b6b84.tar.gz rust-49f01413748f536f49b3d14845dbe5dd717b6b84.zip | |
Implement base_local iteratively
| -rw-r--r-- | src/librustc/mir/mod.rs | 11 |
1 files 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 @@ 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), + } } } |
