Skip to content

Commit 479968b

Browse files
committed
explicitly handle errors in select
1 parent e873eef commit 479968b

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/librustc_trait_selection/traits/select.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use crate::traits::project::ProjectionCacheKeyExt;
3838
use rustc_ast::attr;
3939
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
4040
use rustc_data_structures::stack::ensure_sufficient_stack;
41+
use rustc_errors::ErrorReported;
4142
use rustc_hir as hir;
4243
use rustc_hir::def_id::DefId;
4344
use rustc_hir::lang_items;
@@ -514,17 +515,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
514515

515516
let evaluate = |c: &'tcx ty::Const<'tcx>| {
516517
if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = c.val {
517-
match self.infcx.const_eval_resolve(
518-
obligation.param_env,
519-
def_id,
520-
substs,
521-
promoted,
522-
Some(obligation.cause.span),
523-
) {
524-
Ok(val) => Ok(ty::Const::from_value(self.tcx(), val, c.ty)),
525-
Err(ErrorHandled::TooGeneric) => Err(EvaluatedToAmbig),
526-
Err(_) => Err(EvaluatedToErr),
527-
}
518+
self.infcx
519+
.const_eval_resolve(
520+
obligation.param_env,
521+
def_id,
522+
substs,
523+
promoted,
524+
Some(obligation.cause.span),
525+
)
526+
.map(|val| ty::Const::from_value(self.tcx(), val, c.ty))
528527
} else {
529528
Ok(c)
530529
}
@@ -537,8 +536,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
537536
Err(_) => Ok(EvaluatedToErr),
538537
}
539538
}
540-
(Err(EvaluatedToErr), _) | (_, Err(EvaluatedToErr)) => Ok(EvaluatedToErr),
541-
_ => Ok(EvaluatedToAmbig),
539+
(Err(ErrorHandled::Reported(ErrorReported)), _)
540+
| (_, Err(ErrorHandled::Reported(ErrorReported))) => Ok(EvaluatedToErr),
541+
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => span_bug!(
542+
obligation.cause.span(self.tcx()),
543+
"ConstEquate: const_eval_resolve returned an unexpected error"
544+
),
545+
(Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
546+
Ok(EvaluatedToAmbig)
547+
}
542548
}
543549
}
544550
}

0 commit comments

Comments
 (0)