@@ -629,8 +629,22 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
629629 & mut self ,
630630 obligation : & PredicateObligation < ' tcx > ,
631631 ) -> Result < EvaluationResult , OverflowError > {
632- self . infcx . probe ( |_| {
633- self . evaluate_predicate_recursively ( TraitObligationStackList :: empty ( ) , obligation)
632+ self . evaluation_probe ( |this| {
633+ this. evaluate_predicate_recursively ( TraitObligationStackList :: empty ( ) , obligation)
634+ } )
635+ }
636+
637+ fn evaluation_probe (
638+ & mut self ,
639+ op : impl FnOnce ( & mut Self ) -> Result < EvaluationResult , OverflowError > ,
640+ ) -> Result < EvaluationResult , OverflowError > {
641+ self . infcx . probe ( |snapshot| -> Result < EvaluationResult , OverflowError > {
642+ let result = op ( self ) ?;
643+ if !self . infcx . region_constraints_added_in_snapshot ( snapshot) {
644+ Ok ( result)
645+ } else {
646+ Ok ( result. max ( EvaluatedToOkModuloRegions ) )
647+ }
634648 } )
635649 }
636650
@@ -988,10 +1002,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
9881002 "evaluate_candidate: depth={} candidate={:?}" ,
9891003 stack. obligation. recursion_depth, candidate
9901004 ) ;
991- let result = self . infcx . probe ( |_ | {
1005+ let result = self . evaluation_probe ( |this | {
9921006 let candidate = ( * candidate) . clone ( ) ;
993- match self . confirm_candidate ( stack. obligation , candidate) {
994- Ok ( selection) => self . evaluate_predicates_recursively (
1007+ match this . confirm_candidate ( stack. obligation , candidate) {
1008+ Ok ( selection) => this . evaluate_predicates_recursively (
9951009 stack. list ( ) ,
9961010 selection. nested_obligations ( ) . iter ( ) ,
9971011 ) ,
@@ -1775,10 +1789,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17751789 stack : & TraitObligationStack < ' o , ' tcx > ,
17761790 where_clause_trait_ref : ty:: PolyTraitRef < ' tcx > ,
17771791 ) -> Result < EvaluationResult , OverflowError > {
1778- self . infcx . probe ( |_ | {
1779- match self . match_where_clause_trait_ref ( stack. obligation , where_clause_trait_ref) {
1792+ self . evaluation_probe ( |this | {
1793+ match this . match_where_clause_trait_ref ( stack. obligation , where_clause_trait_ref) {
17801794 Ok ( obligations) => {
1781- self . evaluate_predicates_recursively ( stack. list ( ) , obligations. iter ( ) )
1795+ this . evaluate_predicates_recursively ( stack. list ( ) , obligations. iter ( ) )
17821796 }
17831797 Err ( ( ) ) => Ok ( EvaluatedToErr ) ,
17841798 }
0 commit comments