]> git.lizzy.rs Git - rust.git/commitdiff
Add `Place` getter to `Operand`
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Fri, 24 Jan 2020 23:30:51 +0000 (15:30 -0800)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Fri, 14 Feb 2020 02:42:12 +0000 (18:42 -0800)
src/librustc/mir/mod.rs

index f6c7174649fe8338333cffdf44155c62811fb407..d3a6ff654d60eed93ed874c880e9729a21f3c2fb 100644 (file)
@@ -1993,6 +1993,15 @@ pub fn to_copy(&self) -> Self {
             Operand::Move(place) => Operand::Copy(place),
         }
     }
+
+    /// Returns the `Place` that is the target of this `Operand`, or `None` if this `Operand` is a
+    /// constant.
+    pub fn place(&self) -> Option<&Place<'tcx>> {
+        match self {
+            Operand::Copy(place) | Operand::Move(place) => Some(place),
+            Operand::Constant(_) => None,
+        }
+    }
 }
 
 ///////////////////////////////////////////////////////////////////////////