mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Add helper for getting an int
out of a Scalar
This commit is contained in:
parent
f03b18b99b
commit
500af76831
@ -357,6 +357,14 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
self.to_bits(target_size).expect("expected Raw bits but got a Pointer")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn assert_int(self) -> ScalarInt {
|
||||
match self {
|
||||
Scalar::Ptr(_) => bug!("expected an int but got an abstract pointer"),
|
||||
Scalar::Int(int) => int,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn assert_ptr(self) -> Pointer<Tag> {
|
||||
match self {
|
||||
|
@ -211,10 +211,7 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
|
||||
#[inline]
|
||||
pub fn to_const_int(self) -> ConstInt {
|
||||
assert!(self.layout.ty.is_integral());
|
||||
let int = match self.to_scalar().expect("to_const_int doesn't work on scalar pairs") {
|
||||
Scalar::Int(int) => int,
|
||||
Scalar::Ptr(_) => bug!("to_const_int doesn't work on pointers"),
|
||||
};
|
||||
let int = self.to_scalar().expect("to_const_int doesn't work on scalar pairs").assert_int();
|
||||
ConstInt::new(int, self.layout.ty.is_signed(), self.layout.ty.is_ptr_sized_integral())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user