diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 2fcb0255cc8..e44b1dc886b 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1910,8 +1910,8 @@ pub fn print_miri_value(value: Value, ty: Ty, f: &mut W) -> fmt::Resul let ty = tcx.lift_to_global(&ty).unwrap(); tcx.layout_of(ty::ParamEnv::empty().and(ty)).unwrap().size.bits() }); - let amt = 128 - bit_width; - write!(f, "{:?}{}", ((bits as i128) << amt) >> amt, i) + let shift = 128 - bit_width; + write!(f, "{:?}{}", ((bits as i128) << shift) >> shift, i) }, (Value::Scalar(Scalar::Bits { bits, .. }), &TyChar) => write!(f, "{:?}", ::std::char::from_u32(bits as u32).unwrap()), diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 524687f6ba7..3347d47a4e8 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -1827,8 +1827,8 @@ impl<'tcx> Const<'tcx> { let size = tcx.layout_of(ty).unwrap_or_else(|e| { panic!("could not compute layout for {:?}: {:?}", ty, e) }).size; - let amt = 128 - size.bits(); - let truncated = (bits << amt) >> amt; + let shift = 128 - size.bits(); + let truncated = (bits << shift) >> shift; assert_eq!(truncated, bits, "from_bits called with untruncated value"); Self::from_scalar(tcx, Scalar::Bits { bits, defined: size.bits() as u8 }, ty.value) } diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index e3db4972edc..9b7443f97ef 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -68,14 +68,14 @@ impl<'tcx> Discr<'tcx> { }; let bit_size = int.size().bits(); - let amt = 128 - bit_size; + let shift = 128 - bit_size; if signed { let sext = |u| { let i = u as i128; - (i << amt) >> amt + (i << shift) >> shift }; let min = sext(1_u128 << (bit_size - 1)); - let max = i128::max_value() >> amt; + let max = i128::max_value() >> shift; let val = sext(self.val); assert!(n < (i128::max_value() as u128)); let n = n as i128; @@ -87,13 +87,13 @@ impl<'tcx> Discr<'tcx> { }; // zero the upper bits let val = val as u128; - let val = (val << amt) >> amt; + let val = (val << shift) >> shift; (Self { val: val as u128, ty: self.ty, }, oflo) } else { - let max = u128::max_value() >> amt; + let max = u128::max_value() >> shift; let val = self.val; let oflo = val > max - n; let val = if oflo { diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index e1ee4ebd70b..8ff1738394e 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -158,9 +158,9 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> { let trunc = |n| { let param_ty = self.param_env.and(self.tcx.lift_to_global(&ty).unwrap()); let bit_width = self.tcx.layout_of(param_ty).unwrap().size.bits(); - trace!("trunc {} with size {} and amt {}", n, bit_width, 128 - bit_width); - let amt = 128 - bit_width; - let result = (n << amt) >> amt; + trace!("trunc {} with size {} and shift {}", n, bit_width, 128 - bit_width); + let shift = 128 - bit_width; + let result = (n << shift) >> shift; trace!("trunc result: {}", result); ConstValue::Scalar(Scalar::Bits { bits: result, diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 983d777ef9b..9f6e376d306 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -930,17 +930,17 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M let i = raw_discr.to_bits(discr.size)? as i128; // going from layout tag type to typeck discriminant type // requires first sign extending with the layout discriminant - let amt = 128 - discr.size.bits(); - let sexted = (i << amt) >> amt; + let shift = 128 - discr.size.bits(); + let sexted = (i << shift) >> shift; // and then zeroing with the typeck discriminant type let discr_ty = ty .ty_adt_def().expect("tagged layout corresponds to adt") .repr .discr_type(); let discr_ty = layout::Integer::from_attr(self.tcx.tcx, discr_ty); - let amt = 128 - discr_ty.size().bits(); + let shift = 128 - discr_ty.size().bits(); let truncatee = sexted as u128; - (truncatee << amt) >> amt + (truncatee << shift) >> shift } else { raw_discr.to_bits(discr.size)? } @@ -1005,8 +1005,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M // their computation, but the in-memory tag is the smallest possible // representation let size = tag.value.size(self.tcx.tcx).bits(); - let amt = 128 - size; - let discr_val = (discr_val << amt) >> amt; + let shift = 128 - size; + let discr_val = (discr_val << shift) >> shift; let (discr_dest, tag) = self.place_field(dest, mir::Field::new(0), layout)?; self.write_scalar(discr_dest, Scalar::Bits { diff --git a/src/librustc_mir/interpret/mod.rs b/src/librustc_mir/interpret/mod.rs index d39bae5e8db..b5b4ac6df6b 100644 --- a/src/librustc_mir/interpret/mod.rs +++ b/src/librustc_mir/interpret/mod.rs @@ -43,17 +43,17 @@ pub fn sign_extend<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, value: u128, ty: Ty<'t let size = layout.size.bits(); assert!(layout.abi.is_signed()); // sign extend - let amt = 128 - size; + let shift = 128 - size; // shift the unsigned value to the left // and back to the right as signed (essentially fills with FF on the left) - Ok((((value << amt) as i128) >> amt) as u128) + Ok((((value << shift) as i128) >> shift) as u128) } pub fn truncate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, value: u128, ty: Ty<'tcx>) -> EvalResult<'tcx, u128> { let param_env = ParamEnv::empty(); let layout = tcx.layout_of(param_env.and(ty)).map_err(|layout| EvalErrorKind::Layout(layout))?; let size = layout.size.bits(); - let amt = 128 - size; + let shift = 128 - size; // truncate (shift left to drop out leftover values, shift right to fill with zeroes) - Ok((value << amt) >> amt) + Ok((value << shift) >> shift) }