about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Poveda <git@christianpoveda.xyz>2019-12-22 08:22:14 -0500
committerChristian Poveda <git@christianpoveda.xyz>2019-12-22 08:29:46 -0500
commit683c4c788f36d67fbc873629b431105c7758dd68 (patch)
tree080fcba8c303a3ad683782b7252aa327bf188722
parent309f437e1d20ce93597eec0514a9cb80150d8861 (diff)
downloadrust-683c4c788f36d67fbc873629b431105c7758dd68.tar.gz
rust-683c4c788f36d67fbc873629b431105c7758dd68.zip
Add error message if `Scalar::from_(u)int` fails
-rw-r--r--src/librustc/mir/interpret/value.rs10
-rw-r--r--src/librustc_mir/interpret/operand.rs4
2 files changed, 10 insertions, 4 deletions
diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs
index 8f5fab4b002..f48d22291c6 100644
--- a/src/librustc/mir/interpret/value.rs
+++ b/src/librustc/mir/interpret/value.rs
@@ -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]
diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs
index 8dd50958350..294b361ee27 100644
--- a/src/librustc_mir/interpret/operand.rs
+++ b/src/librustc_mir/interpret/operand.rs
@@ -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]