From adf4ef7b98212e1295e7cbc68a7133e67f9af846 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 2 Jul 2018 02:12:19 +0100 Subject: [PATCH] Use LitToConstError rather than bool for errors --- src/librustc/ty/layout.rs | 5 +---- src/librustc_mir/hair/pattern/mod.rs | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 0763c8af5d0..a32fdbb285d 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1115,13 +1115,10 @@ enum StructKind { } tcx.layout_raw(param_env.and(normalized))? } - ty::TyParam(_) => { - return Err(LayoutError::Unknown(ty)); - } ty::TyGeneratorWitness(..) | ty::TyInfer(_) => { bug!("LayoutDetails::compute: unexpected type `{}`", ty) } - ty::TyError => { + ty::TyParam(_) | ty::TyError => { return Err(LayoutError::Unknown(ty)); } }) diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 2291387792b..636969e2632 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -743,8 +743,8 @@ fn lower_lit(&mut self, expr: &'tcx hir::Expr) -> PatternKind<'tcx> { ); *self.const_to_pat(instance, val, expr.hir_id, lit.span).kind }, - Err(float_bug) => { - if float_bug { + Err(e) => { + if e == LitToConstError::UnparseableFloat { self.errors.push(PatternError::FloatBug); } PatternKind::Wild @@ -766,8 +766,8 @@ fn lower_lit(&mut self, expr: &'tcx hir::Expr) -> PatternKind<'tcx> { ); *self.const_to_pat(instance, val, expr.hir_id, lit.span).kind }, - Err(float_bug) => { - if float_bug { + Err(e) => { + if e == LitToConstError::UnparseableFloat { self.errors.push(PatternError::FloatBug); } PatternKind::Wild @@ -1122,12 +1122,18 @@ pub fn compare_const_vals<'a, 'tcx>( fallback() } +#[derive(PartialEq)] +enum LitToConstError { + UnparseableFloat, + Propagated, +} + // FIXME: Combine with rustc_mir::hair::cx::const_eval_literal fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind, tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>, neg: bool) - -> Result<&'tcx ty::Const<'tcx>, bool> { + -> Result<&'tcx ty::Const<'tcx>, LitToConstError> { use syntax::ast::*; use rustc::mir::interpret::*; @@ -1156,11 +1162,10 @@ enum Int { ty::TyInt(other) => Int::Signed(other), ty::TyUint(UintTy::Usize) => Int::Unsigned(tcx.sess.target.usize_ty), ty::TyUint(other) => Int::Unsigned(other), - ty::TyError => { - // Avoid ICE - return Err(false); + ty::TyError => { // Avoid ICE (#51963) + return Err(LitToConstError::Propagated); } - _ => bug!("{:?}", ty.sty), + _ => bug!("literal integer type with bad type ({:?})", ty.sty), }; // This converts from LitKind::Int (which is sign extended) to // Scalar::Bytes (which is zero extended) @@ -1190,14 +1195,14 @@ enum Int { }) }, LitKind::Float(n, fty) => { - parse_float(n, fty, neg).map_err(|_| true)? + parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)? } LitKind::FloatUnsuffixed(n) => { let fty = match ty.sty { ty::TyFloat(fty) => fty, _ => bug!() }; - parse_float(n, fty, neg).map_err(|_| true)? + parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)? } LitKind::Bool(b) => ConstValue::Scalar(Scalar::Bits { bits: b as u128, -- 2.44.0