Change results to options
This commit is contained in:
parent
90686ded25
commit
309f437e1d
@ -237,12 +237,12 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn try_from_uint(i: impl Into<u128>, size: Size) -> InterpResult<'tcx, Self> {
|
||||
pub fn try_from_uint(i: impl Into<u128>, size: Size) -> Option<Self> {
|
||||
let i = i.into();
|
||||
if truncate(i, size) == i {
|
||||
Ok(Scalar::Raw { data: i, size: size.bytes() as u8 })
|
||||
Some(Scalar::Raw { data: i, size: size.bytes() as u8 })
|
||||
} else {
|
||||
throw_unsup_format!("Unsigned value {:#x} does not fit in {} bits", i, size.bits())
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,14 +272,14 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn try_from_int(i: impl Into<i128>, size: Size) -> InterpResult<'tcx, Self> {
|
||||
pub fn try_from_int(i: impl Into<i128>, size: Size) -> Option<Self> {
|
||||
let i = i.into();
|
||||
// `into` performed sign extension, we have to truncate
|
||||
let truncated = truncate(i as u128, size);
|
||||
if sign_extend(truncated, size) as i128 == i {
|
||||
Ok(Scalar::Raw { data: truncated, size: size.bytes() as u8 })
|
||||
Some(Scalar::Raw { data: truncated, size: size.bytes() as u8 })
|
||||
} else {
|
||||
throw_unsup_format!("Signed value {:#x} does not fit in {} bits", i, size.bits())
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,8 +219,8 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn try_from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> InterpResult<'tcx, Self> {
|
||||
Ok(Self::from_scalar(Scalar::try_from_uint(i, layout.size)?, layout))
|
||||
pub fn try_from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> Option<Self> {
|
||||
Some(Self::from_scalar(Scalar::try_from_uint(i, layout.size)?, layout))
|
||||
}
|
||||
#[inline]
|
||||
pub fn from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> Self {
|
||||
@ -228,8 +228,8 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn try_from_int(i: impl Into<i128>, layout: TyLayout<'tcx>) -> InterpResult<'tcx, Self> {
|
||||
Ok(Self::from_scalar(Scalar::try_from_int(i, layout.size)?, layout))
|
||||
pub fn try_from_int(i: impl Into<i128>, layout: TyLayout<'tcx>) -> Option<Self> {
|
||||
Some(Self::from_scalar(Scalar::try_from_int(i, layout.size)?, layout))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
Loading…
Reference in New Issue
Block a user