From 0a2a517fe60caa35aea463d2e32a7a7193724053 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 17 Aug 2019 12:06:05 +0200 Subject: [PATCH] Add ImmTy::from_uint --- src/librustc_mir/interpret/operand.rs | 13 +++++++++++-- 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,13 +187,22 @@ impl<'tcx, Tag> From> 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, layout: TyLayout<'tcx>) -> Self { ImmTy { imm: val.into(), layout } } + #[inline] + pub fn from_uint(i: impl Into, layout: TyLayout<'tcx>) -> Self { + Self::from_scalar(Scalar::from_uint(i, layout.size), layout) + } + + #[inline] + pub fn from_int(i: impl Into, 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];