diff options
| -rw-r--r-- | src/librustc_mir/interpret/operand.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 48e7193ec39..072152a3887 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -219,13 +219,22 @@ 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)) + } + #[inline] pub fn from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> Self { - Self::from_scalar(Scalar::from_uint(i, layout.size), layout) + Self::try_from_uint(i, layout).unwrap() + } + + #[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)) } #[inline] pub fn from_int(i: impl Into<i128>, layout: TyLayout<'tcx>) -> Self { - Self::from_scalar(Scalar::from_int(i, layout.size), layout) + Self::try_from_int(i, layout).unwrap() } #[inline] |
