Skip to content

Commit eaf8cda

Browse files
committed
add helper methods on ValTree
1 parent 2bc59c7 commit eaf8cda

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

compiler/rustc_middle/src/ty/consts/valtree.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,20 @@ impl<'tcx> ValTree<'tcx> {
3131
pub fn zst() -> Self {
3232
Self::Branch(&[])
3333
}
34+
35+
#[inline]
36+
pub fn unwrap_leaf(self) -> ScalarInt {
37+
match self {
38+
Self::Leaf(s) => s,
39+
_ => bug!("expected leaf, got {:?}", self),
40+
}
41+
}
42+
43+
#[inline]
44+
pub fn unwrap_branch(self) -> &'tcx [Self] {
45+
match self {
46+
Self::Branch(branch) => branch,
47+
_ => bug!("expected branch, got {:?}", self),
48+
}
49+
}
3450
}

0 commit comments

Comments
 (0)