@@ -629,8 +629,22 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
629
629
& mut self ,
630
630
obligation : & PredicateObligation < ' tcx > ,
631
631
) -> 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
+ }
634
648
} )
635
649
}
636
650
@@ -988,10 +1002,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
988
1002
"evaluate_candidate: depth={} candidate={:?}" ,
989
1003
stack. obligation. recursion_depth, candidate
990
1004
) ;
991
- let result = self . infcx . probe ( |_ | {
1005
+ let result = self . evaluation_probe ( |this | {
992
1006
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 (
995
1009
stack. list ( ) ,
996
1010
selection. nested_obligations ( ) . iter ( ) ,
997
1011
) ,
@@ -1775,10 +1789,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1775
1789
stack : & TraitObligationStack < ' o , ' tcx > ,
1776
1790
where_clause_trait_ref : ty:: PolyTraitRef < ' tcx > ,
1777
1791
) -> 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) {
1780
1794
Ok ( obligations) => {
1781
- self . evaluate_predicates_recursively ( stack. list ( ) , obligations. iter ( ) )
1795
+ this . evaluate_predicates_recursively ( stack. list ( ) , obligations. iter ( ) )
1782
1796
}
1783
1797
Err ( ( ) ) => Ok ( EvaluatedToErr ) ,
1784
1798
}
0 commit comments