From: Dylan MacKenzie Date: Tue, 30 Nov 2021 22:56:26 +0000 (-0800) Subject: Add "is" methods for projections to a given index X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;ds=sidebyside;h=d7077073648041ec505629b2f1df9ab800c422e2;p=rust.git Add "is" methods for projections to a given index --- diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index a05b8a1da8d..9fc12ad4a0b 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -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