]> git.lizzy.rs Git - rust.git/commitdiff
add a `first_free_index` parameter
authorNiko Matsakis <niko@alum.mit.edu>
Fri, 31 Aug 2018 19:41:27 +0000 (15:41 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Sun, 9 Sep 2018 18:14:41 +0000 (14:14 -0400)
src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs

index 0e945ad33419e0b35f073a31375e3ee36f6eddcc..217ec45320e00685cf10ae72949327d7060a52e1 100644 (file)
@@ -203,15 +203,15 @@ fn create_scope(
     /// the region with; to do so, it indexes backwards into the list
     /// of ambient scopes `scopes`.
     fn lookup_bound_region(
-        &self,
         debruijn: ty::DebruijnIndex,
         br: &ty::BoundRegion,
+        first_free_index: ty::DebruijnIndex,
         scopes: &[BoundRegionScope],
     ) -> RegionVid {
         // The debruijn index is a "reverse index" into the
         // scopes listing. So when we have INNERMOST (0), we
         // want the *last* scope pushed, and so forth.
-        let debruijn_index = debruijn.index() - ty::INNERMOST.index();
+        let debruijn_index = debruijn.index() - first_free_index.index();
         let scope = &scopes[scopes.len() - debruijn_index - 1];
 
         // Find this bound region in that scope to map to a
@@ -226,10 +226,13 @@ fn replace_bound_region(
         &self,
         universal_regions: &UniversalRegions<'tcx>,
         r: ty::Region<'tcx>,
+        first_free_index: ty::DebruijnIndex,
         scopes: &[BoundRegionScope],
     ) -> RegionVid {
         match r {
-            ty::ReLateBound(debruijn, br) => self.lookup_bound_region(*debruijn, br, scopes),
+            ty::ReLateBound(debruijn, br) => {
+                Self::lookup_bound_region(*debruijn, br, first_free_index, scopes)
+            }
 
             ty::ReVar(v) => *v,
 
@@ -380,8 +383,10 @@ fn regions(
                 a, b, self.ambient_variance
             );
 
-            let v_a = self.replace_bound_region(universal_regions, a, &self.a_scopes);
-            let v_b = self.replace_bound_region(universal_regions, b, &self.b_scopes);
+            let v_a =
+                self.replace_bound_region(universal_regions, a, ty::INNERMOST, &self.a_scopes);
+            let v_b =
+                self.replace_bound_region(universal_regions, b, ty::INNERMOST, &self.b_scopes);
 
             debug!("regions: v_a = {:?}", v_a);
             debug!("regions: v_b = {:?}", v_b);