@@ -20,7 +20,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
20
20
& self ,
21
21
obligation : & PredicateObligation < ' tcx > ,
22
22
) -> bool {
23
- self . evaluate_obligation ( obligation) . may_apply ( )
23
+ self . evaluate_obligation_no_overflow ( obligation) . may_apply ( )
24
24
}
25
25
26
26
/// Evaluates whether the predicate can be satisfied in the given
@@ -30,22 +30,31 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
30
30
& self ,
31
31
obligation : & PredicateObligation < ' tcx > ,
32
32
) -> bool {
33
- self . evaluate_obligation ( obligation) == EvaluationResult :: EvaluatedToOk
33
+ self . evaluate_obligation_no_overflow ( obligation) == EvaluationResult :: EvaluatedToOk
34
34
}
35
35
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 (
39
38
& self ,
40
39
obligation : & PredicateObligation < ' tcx > ,
41
- ) -> EvaluationResult {
40
+ ) -> Result < EvaluationResult , OverflowError > {
42
41
let mut _orig_values = SmallVec :: new ( ) ;
43
42
let c_pred = self . canonicalize_query ( & obligation. param_env . and ( obligation. predicate ) ,
44
43
& mut _orig_values) ;
45
44
// Run canonical query. If overflow occurs, rerun from scratch but this time
46
45
// in standard trait query mode so that overflow is handled appropriately
47
46
// 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) {
49
58
Ok ( result) => result,
50
59
Err ( OverflowError ) => {
51
60
let mut selcx =
0 commit comments