diff options
| -rw-r--r-- | src/librustc/ty/layout.rs | 5 | ||||
| -rw-r--r-- | 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 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { } 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 @@ impl<'a, 'tcx> PatternContext<'a, '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 @@ impl<'a, 'tcx> PatternContext<'a, '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 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind, 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 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind, }) }, 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, |
