mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-04 04:39:16 +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")
|
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]
|
#[inline]
|
||||||
pub fn assert_ptr(self) -> Pointer<Tag> {
|
pub fn assert_ptr(self) -> Pointer<Tag> {
|
||||||
match self {
|
match self {
|
||||||
|
@ -211,10 +211,7 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_const_int(self) -> ConstInt {
|
pub fn to_const_int(self) -> ConstInt {
|
||||||
assert!(self.layout.ty.is_integral());
|
assert!(self.layout.ty.is_integral());
|
||||||
let int = match self.to_scalar().expect("to_const_int doesn't work on scalar pairs") {
|
let int = self.to_scalar().expect("to_const_int doesn't work on scalar pairs").assert_int();
|
||||||
Scalar::Int(int) => int,
|
|
||||||
Scalar::Ptr(_) => bug!("to_const_int doesn't work on pointers"),
|
|
||||||
};
|
|
||||||
ConstInt::new(int, self.layout.ty.is_signed(), self.layout.ty.is_ptr_sized_integral())
|
ConstInt::new(int, self.layout.ty.is_signed(), self.layout.ty.is_ptr_sized_integral())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user