Skip to content

Commit

Permalink
add ImmTy::try_from_(u)int methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdrz committed Dec 14, 2019
1 parent 0bce91f commit 90686de
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/librustc_mir/interpret/operand.rs
Expand Up @@ -218,14 +218,23 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
ImmTy { imm: val.into(), layout }
}

#[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]
Expand Down

0 comments on commit 90686de

Please sign in to comment.