about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-07-03 05:59:08 -0400
committerNiko Matsakis <niko@alum.mit.edu>2018-07-03 18:10:08 -0400
commitdddd4075b1cdab90a3bf10f1687f3d0ed2ee5bec (patch)
tree465055d4f622b46d5cc6120bb0148924ed91e801 /src
parent09f431fad5b8d67f278aa3130d3eccd0cd526cce (diff)
downloadrust-dddd4075b1cdab90a3bf10f1687f3d0ed2ee5bec.tar.gz
rust-dddd4075b1cdab90a3bf10f1687f3d0ed2ee5bec.zip
generalize `find_constraint_paths_between_regions`
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/borrow_check/nll/region_infer/error_reporting.rs27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting.rs
index d8258afc24f..85df5ec9429 100644
--- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting.rs
+++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting.rs
@@ -64,13 +64,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
     fn find_constraint_paths_between_regions(
         &self,
         from_region: RegionVid,
-        to_region: RegionVid,
+        target_test: impl Fn(RegionVid) -> bool,
     ) -> Vec<Vec<ConstraintIndex>> {
         let mut results = vec![];
         self.find_constraint_paths_between_regions_helper(
             from_region,
             from_region,
-            to_region,
+            &target_test,
             &mut FxHashSet::default(),
             &mut vec![],
             &mut results,
@@ -83,7 +83,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         &self,
         from_region: RegionVid,
         current_region: RegionVid,
-        to_region: RegionVid,
+        target_test: &impl Fn(RegionVid) -> bool,
         visited: &mut FxHashSet<RegionVid>,
         stack: &mut Vec<ConstraintIndex>,
         results: &mut Vec<Vec<ConstraintIndex>>,
@@ -96,18 +96,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         }
 
         // Check if we reached the region we were looking for.
-        if current_region == to_region {
-            // Unless we started out searching for `'a ~> 'a`, which shouldn't have caused
-            // en error, then we must have traversed at least *some* constraint:
-            assert!(!stack.is_empty());
-
-            // The first constraint should be like `X: from_region`.
-            assert_eq!(self.constraints[stack[0]].sub, from_region);
-
-            // The last constraint should be like `to_region: Y`.
-            assert_eq!(self.constraints[*stack.last().unwrap()].sup, to_region);
-
-            results.push(stack.clone());
+        if target_test(current_region) {
+            if !stack.is_empty() {
+                assert_eq!(self.constraints[stack[0]].sub, from_region);
+                results.push(stack.clone());
+            }
             return;
         }
 
@@ -118,7 +111,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
                 self.find_constraint_paths_between_regions_helper(
                     from_region,
                     self.constraints[constraint].sup,
-                    to_region,
+                    target_test,
                     visited,
                     stack,
                     results,
@@ -229,7 +222,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         };
 
         // Find all paths
-        let constraint_paths = self.find_constraint_paths_between_regions(outlived_fr, fr);
+        let constraint_paths = self.find_constraint_paths_between_regions(outlived_fr, |r| r == fr);
         debug!("report_error: constraint_paths={:#?}", constraint_paths);
 
         // Find the shortest such path.