@@ -64,13 +64,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6464 fn find_constraint_paths_between_regions (
6565 & self ,
6666 from_region : RegionVid ,
67- to_region : RegionVid ,
67+ target_test : impl Fn ( RegionVid ) -> bool ,
6868 ) -> Vec < Vec < ConstraintIndex > > {
6969 let mut results = vec ! [ ] ;
7070 self . find_constraint_paths_between_regions_helper (
7171 from_region,
7272 from_region,
73- to_region ,
73+ & target_test ,
7474 & mut FxHashSet :: default ( ) ,
7575 & mut vec ! [ ] ,
7676 & mut results,
@@ -83,7 +83,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
8383 & self ,
8484 from_region : RegionVid ,
8585 current_region : RegionVid ,
86- to_region : RegionVid ,
86+ target_test : & impl Fn ( RegionVid ) -> bool ,
8787 visited : & mut FxHashSet < RegionVid > ,
8888 stack : & mut Vec < ConstraintIndex > ,
8989 results : & mut Vec < Vec < ConstraintIndex > > ,
@@ -96,18 +96,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
9696 }
9797
9898 // 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+ }
111104 return ;
112105 }
113106
@@ -118,7 +111,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
118111 self . find_constraint_paths_between_regions_helper (
119112 from_region,
120113 self . constraints [ constraint] . sup ,
121- to_region ,
114+ target_test ,
122115 visited,
123116 stack,
124117 results,
@@ -229,7 +222,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
229222 } ;
230223
231224 // 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) ;
233226 debug ! ( "report_error: constraint_paths={:#?}" , constraint_paths) ;
234227
235228 // Find the shortest such path.
0 commit comments