X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_mir%2Fhair%2Fconstant.rs;h=a5be55d16d488b7049ce0c5239d2804988b3db99;hb=d59dcb261ecdc47d8afaac532050dadf86f3c898;hp=d2c86d36238e1eeb76358dfe8e9cb0cd32f71a69;hpb=d8b828beea89f1131c878f824cadcf92145f5c3e;p=rust.git diff --git a/src/librustc_mir/hair/constant.rs b/src/librustc_mir/hair/constant.rs index d2c86d36238..a5be55d16d4 100644 --- a/src/librustc_mir/hair/constant.rs +++ b/src/librustc_mir/hair/constant.rs @@ -1,5 +1,5 @@ use syntax::ast; -use rustc::ty::{self, Ty, TyCtxt, ParamEnv}; +use rustc::ty::{self, Ty, TyCtxt, ParamEnv, layout::Size}; use syntax_pos::symbol::Symbol; use rustc::mir::interpret::{ConstValue, Scalar}; @@ -23,23 +23,20 @@ trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits()); let result = truncate(n, width); trace!("trunc result: {}", result); - Ok(ConstValue::Scalar(Scalar::Bits { - bits: result, - size: width.bytes() as u8, - })) + Ok(ConstValue::Scalar(Scalar::from_uint(result, width))) }; use rustc::mir::interpret::*; let lit = match *lit { LitKind::Str(ref s, _) => { let s = s.as_str(); - let allocation = Allocation::from_byte_aligned_bytes(s.as_bytes(), ()); + let allocation = Allocation::from_byte_aligned_bytes(s.as_bytes()); let allocation = tcx.intern_const_alloc(allocation); ConstValue::Slice { data: allocation, start: 0, end: s.len() } }, LitKind::Err(ref s) => { let s = s.as_str(); - let allocation = Allocation::from_byte_aligned_bytes(s.as_bytes(), ()); + let allocation = Allocation::from_byte_aligned_bytes(s.as_bytes()); let allocation = tcx.intern_const_alloc(allocation); return Ok(tcx.mk_const(ty::Const { val: ConstValue::Slice{ data: allocation, start: 0, end: s.len() }, @@ -50,10 +47,7 @@ let id = tcx.allocate_bytes(data); ConstValue::Scalar(Scalar::Ptr(id.into())) }, - LitKind::Byte(n) => ConstValue::Scalar(Scalar::Bits { - bits: n as u128, - size: 1, - }), + LitKind::Byte(n) => ConstValue::Scalar(Scalar::from_uint(n, Size::from_bytes(1))), LitKind::Int(n, _) if neg => { let n = n as i128; let n = n.overflowing_neg().0; @@ -84,7 +78,7 @@ fn parse_float<'tcx>( let num = num.as_str(); use rustc_apfloat::ieee::{Single, Double}; use rustc_apfloat::Float; - let (bits, size) = match fty { + let (data, size) = match fty { ast::FloatTy::F32 => { num.parse::().map_err(|_| ())?; let mut f = num.parse::().unwrap_or_else(|e| { @@ -107,5 +101,5 @@ fn parse_float<'tcx>( } }; - Ok(ConstValue::Scalar(Scalar::Bits { bits, size })) + Ok(ConstValue::Scalar(Scalar::from_uint(data, Size::from_bytes(size)))) }