Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d707707

Browse files
Add "is" methods for projections to a given index
1 parent bb27b05 commit d707707

File tree

1 file changed

+10
-0
lines changed
  • compiler/rustc_middle/src/mir

1 file changed

+10
-0
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,16 @@ impl<V, T> ProjectionElem<V, T> {
18031803
| Self::Downcast(_, _) => false,
18041804
}
18051805
}
1806+
1807+
/// Returns `true` if this is a `Downcast` projection with the given `VariantIdx`.
1808+
pub fn is_downcast_to(&self, v: VariantIdx) -> bool {
1809+
matches!(*self, Self::Downcast(_, x) if x == v)
1810+
}
1811+
1812+
/// Returns `true` if this is a `Field` projection with the given index.
1813+
pub fn is_field_to(&self, f: Field) -> bool {
1814+
matches!(*self, Self::Field(x, _) if x == f)
1815+
}
18061816
}
18071817

18081818
/// Alias for projections as they appear in places, where the base is a place

0 commit comments

Comments
 (0)