From eaf8cdaa0bcf7bc188da8d8d0a35126cf37b0580 Mon Sep 17 00:00:00 2001 From: b-naber Date: Tue, 12 Apr 2022 15:07:35 +0200 Subject: [PATCH] add helper methods on ValTree --- compiler/rustc_middle/src/ty/consts/valtree.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/compiler/rustc_middle/src/ty/consts/valtree.rs b/compiler/rustc_middle/src/ty/consts/valtree.rs index 195760c05908..e17c69cb3537 100644 --- a/compiler/rustc_middle/src/ty/consts/valtree.rs +++ b/compiler/rustc_middle/src/ty/consts/valtree.rs @@ -31,4 +31,20 @@ impl<'tcx> ValTree<'tcx> { pub fn zst() -> Self { Self::Branch(&[]) } + + #[inline] + pub fn unwrap_leaf(self) -> ScalarInt { + match self { + Self::Leaf(s) => s, + _ => bug!("expected leaf, got {:?}", self), + } + } + + #[inline] + pub fn unwrap_branch(self) -> &'tcx [Self] { + match self { + Self::Branch(branch) => branch, + _ => bug!("expected branch, got {:?}", self), + } + } }