@@ -64,13 +64,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
64
64
fn find_constraint_paths_between_regions (
65
65
& self ,
66
66
from_region : RegionVid ,
67
- to_region : RegionVid ,
67
+ target_test : impl Fn ( RegionVid ) -> bool ,
68
68
) -> Vec < Vec < ConstraintIndex > > {
69
69
let mut results = vec ! [ ] ;
70
70
self . find_constraint_paths_between_regions_helper (
71
71
from_region,
72
72
from_region,
73
- to_region ,
73
+ & target_test ,
74
74
& mut FxHashSet :: default ( ) ,
75
75
& mut vec ! [ ] ,
76
76
& mut results,
@@ -83,7 +83,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
83
83
& self ,
84
84
from_region : RegionVid ,
85
85
current_region : RegionVid ,
86
- to_region : RegionVid ,
86
+ target_test : & impl Fn ( RegionVid ) -> bool ,
87
87
visited : & mut FxHashSet < RegionVid > ,
88
88
stack : & mut Vec < ConstraintIndex > ,
89
89
results : & mut Vec < Vec < ConstraintIndex > > ,
@@ -96,18 +96,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
96
96
}
97
97
98
98
// Check if we reached the region we were looking for.
99
- if current_region == to_region {
100
- // Unless we started out searching for `'a ~> 'a`, which shouldn't have caused
101
- // en error, then we must have traversed at least *some* constraint:
102
- assert ! ( !stack. is_empty( ) ) ;
103
-
104
- // The first constraint should be like `X: from_region`.
105
- assert_eq ! ( self . constraints[ stack[ 0 ] ] . sub, from_region) ;
106
-
107
- // The last constraint should be like `to_region: Y`.
108
- assert_eq ! ( self . constraints[ * stack. last( ) . unwrap( ) ] . sup, to_region) ;
109
-
110
- results. push ( stack. clone ( ) ) ;
99
+ if target_test ( current_region) {
100
+ if !stack. is_empty ( ) {
101
+ assert_eq ! ( self . constraints[ stack[ 0 ] ] . sub, from_region) ;
102
+ results. push ( stack. clone ( ) ) ;
103
+ }
111
104
return ;
112
105
}
113
106
@@ -118,7 +111,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
118
111
self . find_constraint_paths_between_regions_helper (
119
112
from_region,
120
113
self . constraints [ constraint] . sup ,
121
- to_region ,
114
+ target_test ,
122
115
visited,
123
116
stack,
124
117
results,
@@ -229,7 +222,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
229
222
} ;
230
223
231
224
// Find all paths
232
- let constraint_paths = self . find_constraint_paths_between_regions ( outlived_fr, fr) ;
225
+ let constraint_paths = self . find_constraint_paths_between_regions ( outlived_fr, |r| r == fr) ;
233
226
debug ! ( "report_error: constraint_paths={:#?}" , constraint_paths) ;
234
227
235
228
// Find the shortest such path.
0 commit comments