Add error message if Scalar::from_(u)int
fails
This commit is contained in:
parent
309f437e1d
commit
683c4c788f
@ -248,7 +248,10 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
|
||||
#[inline]
|
||||
pub fn from_uint(i: impl Into<u128>, size: Size) -> Self {
|
||||
Self::try_from_uint(i, size).unwrap()
|
||||
let i = i.into();
|
||||
Self::try_from_uint(i, size).unwrap_or_else(|| {
|
||||
bug!("Unsigned value {:#x} does not fit in {} bits", i, size.bits())
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -285,7 +288,10 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
|
||||
#[inline]
|
||||
pub fn from_int(i: impl Into<i128>, size: Size) -> Self {
|
||||
Self::try_from_int(i, size).unwrap()
|
||||
let i = i.into();
|
||||
Self::try_from_int(i, size).unwrap_or_else(|| {
|
||||
bug!("Signed value {:#x} does not fit in {} bits", i, size.bits())
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -224,7 +224,7 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
|
||||
}
|
||||
#[inline]
|
||||
pub fn from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> Self {
|
||||
Self::try_from_uint(i, layout).unwrap()
|
||||
Self::from_scalar(Scalar::from_uint(i, layout.size), layout)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -234,7 +234,7 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
|
||||
|
||||
#[inline]
|
||||
pub fn from_int(i: impl Into<i128>, layout: TyLayout<'tcx>) -> Self {
|
||||
Self::try_from_int(i, layout).unwrap()
|
||||
Self::from_scalar(Scalar::from_int(i, layout.size), layout)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
Loading…
Reference in New Issue
Block a user