]> git.lizzy.rs Git - rust.git/commitdiff
Use LitToConstError rather than bool for errors
authorvarkor <github@varkor.com>
Mon, 2 Jul 2018 01:12:19 +0000 (02:12 +0100)
committervarkor <github@varkor.com>
Mon, 2 Jul 2018 18:44:27 +0000 (19:44 +0100)
src/librustc/ty/layout.rs
src/librustc_mir/hair/pattern/mod.rs

index 0763c8af5d037a02d69e2ed51b5af57ef475915e..a32fdbb285d12cdae128c30dcf4a80077589893b 100644 (file)
@@ -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));
             }
         })
index 2291387792b0e2c689066cf4b946e2d7deaab749..636969e263222d81e942aa9ea847babf0a062343 100644 (file)
@@ -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,