about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2018-10-16 15:39:07 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2018-10-16 16:57:26 +0200
commit44a2f681a988eb5587bd98a0cb37730fbd33f576 (patch)
tree28e17c32cf99dbbcb72224d624f8d2577ded3475
parent5ea8eb55cd9f4547b332f43c9f723de30187c223 (diff)
downloadrust-44a2f681a988eb5587bd98a0cb37730fbd33f576.tar.gz
rust-44a2f681a988eb5587bd98a0cb37730fbd33f576.zip
Add `Place::base_local` method and improve doc for `Place::local` to clarify why we need the former.
-rw-r--r--src/librustc/mir/mod.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs
index 2587e19b1cb..883a9d6497b 100644
--- a/src/librustc/mir/mod.rs
+++ b/src/librustc/mir/mod.rs
@@ -1967,7 +1967,10 @@ impl<'tcx> Place<'tcx> {
         Place::Projection(Box::new(PlaceProjection { base: self, elem }))
     }
 
-    /// Find the innermost `Local` from this `Place`.
+    /// Find the innermost `Local` from this `Place`, *if* it is either a local itself or
+    /// a single deref of a local.
+    ///
+    /// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
     pub fn local(&self) -> Option<Local> {
         match self {
             Place::Local(local) |
@@ -1978,6 +1981,15 @@ impl<'tcx> Place<'tcx> {
             _ => None,
         }
     }
+
+    /// Find the innermost `Local` from this `Place`.
+    pub fn base_local(&self) -> Option<Local> {
+        match self {
+            Place::Local(local) => Some(*local),
+            Place::Projection(box Projection { base, elem: _ }) => base.base_local(),
+            Place::Promoted(..) | Place::Static(..) => None,
+        }
+    }
 }
 
 impl<'tcx> Debug for Place<'tcx> {