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 shift {}", n, bit_width, 128 - bit_width);
- let shift = 128 - bit_width;
+ let width = self.tcx.layout_of(param_ty).unwrap().size;
+ trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits());
+ let shift = 128 - width.bits();
let result = (n << shift) >> shift;
trace!("trunc result: {}", result);
ConstValue::Scalar(Scalar::Bits {
bits: result,
- defined: bit_width as u8,
+ size: width.bytes() as u8,
})
};
let s = s.as_str();
let id = self.tcx.allocate_bytes(s.as_bytes());
let value = Scalar::Ptr(id.into()).to_value_with_len(s.len() as u64, self.tcx);
- ConstValue::from_byval_value(value)
+ ConstValue::from_byval_value(value).unwrap()
},
LitKind::ByteStr(ref data) => {
let id = self.tcx.allocate_bytes(data);
},
LitKind::Byte(n) => ConstValue::Scalar(Scalar::Bits {
bits: n as u128,
- defined: 8,
+ size: 1,
}),
LitKind::Int(n, _) if neg => {
let n = n as i128;
};
parse_float(n, fty)
}
- LitKind::Bool(b) => ConstValue::Scalar(Scalar::Bits {
- bits: b as u128,
- defined: 8,
- }),
- LitKind::Char(c) => ConstValue::Scalar(Scalar::Bits {
- bits: c as u128,
- defined: 32,
- }),
+ LitKind::Bool(b) => ConstValue::Scalar(Scalar::from_bool(b)),
+ LitKind::Char(c) => ConstValue::Scalar(Scalar::from_char(c)),
};
ty::Const::from_const_value(self.tcx, lit, ty)
}