Add error message if Scalar::from_(u)int fails

This commit is contained in:
Christian Poveda 2019-12-22 08:22:14 -05:00
parent 309f437e1d
commit 683c4c788f
No known key found for this signature in database
GPG Key ID: 27525EF5E7420A50
2 changed files with 10 additions and 4 deletions

View File

@ -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]

View File

@ -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]