Skip to content

Commit 0a2a517

Browse files
committed
Add ImmTy::from_uint
1 parent 211d1e0 commit 0a2a517

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/librustc_mir/interpret/operand.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,22 @@ impl<'tcx, Tag> From<ImmTy<'tcx, Tag>> for OpTy<'tcx, Tag> {
187187
}
188188
}
189189

190-
impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag>
191-
{
190+
impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
192191
#[inline]
193192
pub fn from_scalar(val: Scalar<Tag>, layout: TyLayout<'tcx>) -> Self {
194193
ImmTy { imm: val.into(), layout }
195194
}
196195

196+
#[inline]
197+
pub fn from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> Self {
198+
Self::from_scalar(Scalar::from_uint(i, layout.size), layout)
199+
}
200+
201+
#[inline]
202+
pub fn from_int(i: impl Into<i128>, layout: TyLayout<'tcx>) -> Self {
203+
Self::from_scalar(Scalar::from_int(i, layout.size), layout)
204+
}
205+
197206
#[inline]
198207
pub fn to_bits(self) -> InterpResult<'tcx, u128> {
199208
self.to_scalar()?.to_bits(self.layout.size)

src/librustc_mir/interpret/terminator.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use syntax::source_map::Span;
77
use rustc_target::spec::abi::Abi;
88

99
use super::{
10-
InterpResult, PointerArithmetic, Scalar,
10+
InterpResult, PointerArithmetic,
1111
InterpCx, Machine, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup, FnVal,
1212
};
1313

@@ -50,10 +50,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5050

5151
for (index, &const_int) in values.iter().enumerate() {
5252
// Compare using binary_op, to also support pointer values
53-
let const_int = Scalar::from_uint(const_int, discr.layout.size);
5453
let (res, _) = self.binary_op(mir::BinOp::Eq,
5554
discr,
56-
ImmTy::from_scalar(const_int, discr.layout),
55+
ImmTy::from_uint(const_int, discr.layout),
5756
)?;
5857
if res.to_bool()? {
5958
target_block = targets[index];

0 commit comments

Comments
 (0)