diff options
| author | Christian Poveda <git@christianpoveda.xyz> | 2019-12-21 10:27:58 -0500 |
|---|---|---|
| committer | Christian Poveda <git@christianpoveda.xyz> | 2019-12-21 10:27:58 -0500 |
| commit | 309f437e1d20ce93597eec0514a9cb80150d8861 (patch) | |
| tree | 54ce99a44ab2f2f6e7280b1d18bf490470b832b4 | |
| parent | 90686ded25ee4f7f6676141a0413c066a2a4d393 (diff) | |
| download | rust-309f437e1d20ce93597eec0514a9cb80150d8861.tar.gz rust-309f437e1d20ce93597eec0514a9cb80150d8861.zip | |
Change results to options
| -rw-r--r-- | src/librustc/mir/interpret/value.rs | 12 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/operand.rs | 8 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 4f196cda5ae..8f5fab4b002 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -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 } } diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 072152a3887..8dd50958350 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -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] |
