From 42d5cf868c74bcd2eabe2b88430a3427d552cc0c Mon Sep 17 00:00:00 2001 From: kenta7777 Date: Sat, 23 Feb 2019 10:07:09 +0900 Subject: [PATCH] reduce an mir code repetition like (n << amt) >> amt --- src/librustc_mir/interpret/place.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index b29e09900f6b1..0bec0d5eb2052 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -7,6 +7,7 @@ use std::hash::Hash; use rustc::hir; use rustc::mir; +use rustc::mir::interpret::truncate; use rustc::ty::{self, Ty}; use rustc::ty::layout::{self, Size, Align, LayoutOf, TyLayout, HasDataLayout, VariantIdx}; use rustc::ty::TypeFoldable; @@ -959,8 +960,7 @@ where // their computation, but the in-memory tag is the smallest possible // representation let size = tag.value.size(self); - let shift = 128 - size.bits(); - let discr_val = (discr_val << shift) >> shift; + let discr_val = truncate(discr_val, size); let discr_dest = self.place_field(dest, 0)?; self.write_scalar(Scalar::from_uint(discr_val, size), discr_dest)?;