X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_mir%2Fhair%2Fconstant.rs;h=37a2e79dae91ff62d89ff94efebcf2648d1c266c;hb=3836573ae4610f75d41d467e35d855efd6b000b5;hp=69df36348a69e6ffbe47801b1d71cabda1f14a0f;hpb=dae331d921d94da76a4ef240463d8b83b77121fb;p=rust.git diff --git a/src/librustc_mir/hair/constant.rs b/src/librustc_mir/hair/constant.rs index 69df36348a6..37a2e79dae9 100644 --- a/src/librustc_mir/hair/constant.rs +++ b/src/librustc_mir/hair/constant.rs @@ -30,19 +30,10 @@ 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 = tcx.intern_const_alloc(allocation); - return Ok(tcx.mk_const(ty::Const { - val: ConstValue::Slice{ data: allocation, start: 0, end: s.len() }, - ty: tcx.types.err, - })); - }, LitKind::ByteStr(ref data) => { let id = tcx.allocate_bytes(data); ConstValue::Scalar(Scalar::Ptr(id.into())) @@ -66,6 +57,7 @@ } LitKind::Bool(b) => ConstValue::Scalar(Scalar::from_bool(b)), LitKind::Char(c) => ConstValue::Scalar(Scalar::from_char(c)), + LitKind::Err(_) => unreachable!(), }; Ok(tcx.mk_const(ty::Const { val: lit, ty })) } @@ -77,8 +69,7 @@ fn parse_float<'tcx>( ) -> Result, ()> { let num = num.as_str(); use rustc_apfloat::ieee::{Single, Double}; - use rustc_apfloat::Float; - let (data, size) = match fty { + let scalar = match fty { ast::FloatTy::F32 => { num.parse::().map_err(|_| ())?; let mut f = num.parse::().unwrap_or_else(|e| { @@ -87,19 +78,19 @@ fn parse_float<'tcx>( if neg { f = -f; } - (f.to_bits(), 4) + Scalar::from_f32(f) } ast::FloatTy::F64 => { num.parse::().map_err(|_| ())?; let mut f = num.parse::().unwrap_or_else(|e| { - panic!("apfloat::ieee::Single failed to parse `{}`: {:?}", num, e) + panic!("apfloat::ieee::Double failed to parse `{}`: {:?}", num, e) }); if neg { f = -f; } - (f.to_bits(), 8) + Scalar::from_f64(f) } }; - Ok(ConstValue::Scalar(Scalar::from_uint(data, Size::from_bytes(size)))) + Ok(ConstValue::Scalar(scalar)) }