From 309f437e1d20ce93597eec0514a9cb80150d8861 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 21 Dec 2019 10:27:58 -0500 Subject: [PATCH] Change results to options --- src/librustc/mir/interpret/value.rs | 12 ++++++------ 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 4f196cda5ae2..8f5fab4b0029 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -237,12 +237,12 @@ impl<'tcx, Tag> Scalar { } #[inline] - pub fn try_from_uint(i: impl Into, size: Size) -> InterpResult<'tcx, Self> { + pub fn try_from_uint(i: impl Into, size: Size) -> Option { 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 { } #[inline] - pub fn try_from_int(i: impl Into, size: Size) -> InterpResult<'tcx, Self> { + pub fn try_from_int(i: impl Into, size: Size) -> Option { 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 072152a38877..8dd50958350b 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, 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, layout: TyLayout<'tcx>) -> Option { + Some(Self::from_scalar(Scalar::try_from_uint(i, layout.size)?, layout)) } #[inline] pub fn from_uint(i: impl Into, layout: TyLayout<'tcx>) -> Self { @@ -228,8 +228,8 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> { } #[inline] - pub fn try_from_int(i: impl Into, 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, layout: TyLayout<'tcx>) -> Option { + Some(Self::from_scalar(Scalar::try_from_int(i, layout.size)?, layout)) } #[inline]