]> git.lizzy.rs Git - rust.git/commitdiff
Add "is" methods for projections to a given index
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Tue, 30 Nov 2021 22:56:26 +0000 (14:56 -0800)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Wed, 1 Dec 2021 01:17:14 +0000 (17:17 -0800)
compiler/rustc_middle/src/mir/mod.rs

index a05b8a1da8d7f008a8b9def9e6395eccff64ac93..9fc12ad4a0b915f43f6e8b36c56e862ca16e54a8 100644 (file)
@@ -1803,6 +1803,16 @@ fn is_indirect(&self) -> bool {
             | Self::Downcast(_, _) => false,
         }
     }
+
+    /// Returns `true` if this is a `Downcast` projection with the given `VariantIdx`.
+    pub fn is_downcast_to(&self, v: VariantIdx) -> bool {
+        matches!(*self, Self::Downcast(_, x) if x == v)
+    }
+
+    /// Returns `true` if this is a `Field` projection with the given index.
+    pub fn is_field_to(&self, f: Field) -> bool {
+        matches!(*self, Self::Field(x, _) if x == f)
+    }
 }
 
 /// Alias for projections as they appear in places, where the base is a place