Skip to content

Commit 309f437

Browse files
committed
Change results to options
1 parent 90686de commit 309f437

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/librustc/mir/interpret/value.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ impl<'tcx, Tag> Scalar<Tag> {
237237
}
238238

239239
#[inline]
240-
pub fn try_from_uint(i: impl Into<u128>, size: Size) -> InterpResult<'tcx, Self> {
240+
pub fn try_from_uint(i: impl Into<u128>, size: Size) -> Option<Self> {
241241
let i = i.into();
242242
if truncate(i, size) == i {
243-
Ok(Scalar::Raw { data: i, size: size.bytes() as u8 })
243+
Some(Scalar::Raw { data: i, size: size.bytes() as u8 })
244244
} else {
245-
throw_unsup_format!("Unsigned value {:#x} does not fit in {} bits", i, size.bits())
245+
None
246246
}
247247
}
248248

@@ -272,14 +272,14 @@ impl<'tcx, Tag> Scalar<Tag> {
272272
}
273273

274274
#[inline]
275-
pub fn try_from_int(i: impl Into<i128>, size: Size) -> InterpResult<'tcx, Self> {
275+
pub fn try_from_int(i: impl Into<i128>, size: Size) -> Option<Self> {
276276
let i = i.into();
277277
// `into` performed sign extension, we have to truncate
278278
let truncated = truncate(i as u128, size);
279279
if sign_extend(truncated, size) as i128 == i {
280-
Ok(Scalar::Raw { data: truncated, size: size.bytes() as u8 })
280+
Some(Scalar::Raw { data: truncated, size: size.bytes() as u8 })
281281
} else {
282-
throw_unsup_format!("Signed value {:#x} does not fit in {} bits", i, size.bits())
282+
None
283283
}
284284
}
285285

src/librustc_mir/interpret/operand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,17 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
219219
}
220220

221221
#[inline]
222-
pub fn try_from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> InterpResult<'tcx, Self> {
223-
Ok(Self::from_scalar(Scalar::try_from_uint(i, layout.size)?, layout))
222+
pub fn try_from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> Option<Self> {
223+
Some(Self::from_scalar(Scalar::try_from_uint(i, layout.size)?, layout))
224224
}
225225
#[inline]
226226
pub fn from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> Self {
227227
Self::try_from_uint(i, layout).unwrap()
228228
}
229229

230230
#[inline]
231-
pub fn try_from_int(i: impl Into<i128>, layout: TyLayout<'tcx>) -> InterpResult<'tcx, Self> {
232-
Ok(Self::from_scalar(Scalar::try_from_int(i, layout.size)?, layout))
231+
pub fn try_from_int(i: impl Into<i128>, layout: TyLayout<'tcx>) -> Option<Self> {
232+
Some(Self::from_scalar(Scalar::try_from_int(i, layout.size)?, layout))
233233
}
234234

235235
#[inline]

0 commit comments

Comments
 (0)