about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBastian Kauschke <bastian_kauschke@hotmail.de>2020-05-07 12:45:15 +0200
committerBastian Kauschke <bastian_kauschke@hotmail.de>2020-05-17 11:05:05 +0200
commit479968b81259ee7bfd3897cb192ff61b59fb8a8f (patch)
tree6b61a6b6acfb2320302dcb50229693dd8f4d1b0f
parente873eef1e37eb45bdafda02ad4a3a4d599cee401 (diff)
downloadrust-479968b81259ee7bfd3897cb192ff61b59fb8a8f.tar.gz
rust-479968b81259ee7bfd3897cb192ff61b59fb8a8f.zip
explicitly handle errors in `select`
-rw-r--r--src/librustc_trait_selection/traits/select.rs32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/librustc_trait_selection/traits/select.rs b/src/librustc_trait_selection/traits/select.rs
index 4f4942ff596..70c6cbef102 100644
--- a/src/librustc_trait_selection/traits/select.rs
+++ b/src/librustc_trait_selection/traits/select.rs
@@ -38,6 +38,7 @@ use crate::traits::project::ProjectionCacheKeyExt;
 use rustc_ast::attr;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_data_structures::stack::ensure_sufficient_stack;
+use rustc_errors::ErrorReported;
 use rustc_hir as hir;
 use rustc_hir::def_id::DefId;
 use rustc_hir::lang_items;
@@ -514,17 +515,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
 
                 let evaluate = |c: &'tcx ty::Const<'tcx>| {
                     if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = c.val {
-                        match self.infcx.const_eval_resolve(
-                            obligation.param_env,
-                            def_id,
-                            substs,
-                            promoted,
-                            Some(obligation.cause.span),
-                        ) {
-                            Ok(val) => Ok(ty::Const::from_value(self.tcx(), val, c.ty)),
-                            Err(ErrorHandled::TooGeneric) => Err(EvaluatedToAmbig),
-                            Err(_) => Err(EvaluatedToErr),
-                        }
+                        self.infcx
+                            .const_eval_resolve(
+                                obligation.param_env,
+                                def_id,
+                                substs,
+                                promoted,
+                                Some(obligation.cause.span),
+                            )
+                            .map(|val| ty::Const::from_value(self.tcx(), val, c.ty))
                     } else {
                         Ok(c)
                     }
@@ -537,8 +536,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
                             Err(_) => Ok(EvaluatedToErr),
                         }
                     }
-                    (Err(EvaluatedToErr), _) | (_, Err(EvaluatedToErr)) => Ok(EvaluatedToErr),
-                    _ => Ok(EvaluatedToAmbig),
+                    (Err(ErrorHandled::Reported(ErrorReported)), _)
+                    | (_, Err(ErrorHandled::Reported(ErrorReported))) => Ok(EvaluatedToErr),
+                    (Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => span_bug!(
+                        obligation.cause.span(self.tcx()),
+                        "ConstEquate: const_eval_resolve returned an unexpected error"
+                    ),
+                    (Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
+                        Ok(EvaluatedToAmbig)
+                    }
                 }
             }
         }