diff options
| -rw-r--r-- | src/librustc_mir/interpret/operand.rs | 13 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/terminator.rs | 5 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 139a92c7b11..d6f5fecb24c 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -187,14 +187,23 @@ impl<'tcx, Tag> From<ImmTy<'tcx, Tag>> for OpTy<'tcx, Tag> { } } -impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> -{ +impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> { #[inline] pub fn from_scalar(val: Scalar<Tag>, layout: TyLayout<'tcx>) -> Self { ImmTy { imm: val.into(), layout } } #[inline] + pub fn from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> Self { + Self::from_scalar(Scalar::from_uint(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) + } + + #[inline] pub fn to_bits(self) -> InterpResult<'tcx, u128> { self.to_scalar()?.to_bits(self.layout.size) } diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index 1d6b48e9da4..2fb68556c3c 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -7,7 +7,7 @@ use syntax::source_map::Span; use rustc_target::spec::abi::Abi; use super::{ - InterpResult, PointerArithmetic, Scalar, + InterpResult, PointerArithmetic, InterpCx, Machine, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup, FnVal, }; @@ -50,10 +50,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { for (index, &const_int) in values.iter().enumerate() { // Compare using binary_op, to also support pointer values - let const_int = Scalar::from_uint(const_int, discr.layout.size); let (res, _) = self.binary_op(mir::BinOp::Eq, discr, - ImmTy::from_scalar(const_int, discr.layout), + ImmTy::from_uint(const_int, discr.layout), )?; if res.to_bool()? { target_block = targets[index]; |
