@@ -20,7 +20,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
2020 & self ,
2121 obligation : & PredicateObligation < ' tcx > ,
2222 ) -> bool {
23- self . evaluate_obligation ( obligation) . may_apply ( )
23+ self . evaluate_obligation_no_overflow ( obligation) . may_apply ( )
2424 }
2525
2626 /// Evaluates whether the predicate can be satisfied in the given
@@ -30,22 +30,31 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
3030 & self ,
3131 obligation : & PredicateObligation < ' tcx > ,
3232 ) -> bool {
33- self . evaluate_obligation ( obligation) == EvaluationResult :: EvaluatedToOk
33+ self . evaluate_obligation_no_overflow ( obligation) == EvaluationResult :: EvaluatedToOk
3434 }
3535
36- // Helper function that canonicalizes and runs the query, as well as handles
37- // overflow.
38- fn evaluate_obligation (
36+ /// Evaluate a given predicate, capturing overflow and propagating it back.
37+ pub fn evaluate_obligation (
3938 & self ,
4039 obligation : & PredicateObligation < ' tcx > ,
41- ) -> EvaluationResult {
40+ ) -> Result < EvaluationResult , OverflowError > {
4241 let mut _orig_values = SmallVec :: new ( ) ;
4342 let c_pred = self . canonicalize_query ( & obligation. param_env . and ( obligation. predicate ) ,
4443 & mut _orig_values) ;
4544 // Run canonical query. If overflow occurs, rerun from scratch but this time
4645 // in standard trait query mode so that overflow is handled appropriately
4746 // within `SelectionContext`.
48- match self . tcx . global_tcx ( ) . evaluate_obligation ( c_pred) {
47+ self . tcx . global_tcx ( ) . evaluate_obligation ( c_pred)
48+ }
49+
50+ // Helper function that canonicalizes and runs the query. If an
51+ // overflow results, we re-run it in the local context so we can
52+ // report a nice error.
53+ fn evaluate_obligation_no_overflow (
54+ & self ,
55+ obligation : & PredicateObligation < ' tcx > ,
56+ ) -> EvaluationResult {
57+ match self . evaluate_obligation ( obligation) {
4958 Ok ( result) => result,
5059 Err ( OverflowError ) => {
5160 let mut selcx =
0 commit comments