summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-05-28 10:13:21 -0400
committerNiko Matsakis <niko@alum.mit.edu>2018-05-28 19:47:04 -0400
commit4aeb6efb6d584ae7632787edff60f3d9e4eb7384 (patch)
tree80eb6ea87da55719ef132aca784c048a7c747cd5 /src
parentrefactor `resolve_lifetime` to track outer-index, not depth (diff)
downloadgrust-4aeb6efb6d584ae7632787edff60f3d9e4eb7384.tar.gz
grust-4aeb6efb6d584ae7632787edff60f3d9e4eb7384.tar.bz2
grust-4aeb6efb6d584ae7632787edff60f3d9e4eb7384.tar.xz
replace use of DebruijnIndex in `for_each_free_region`
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/fold.rs30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs
index df8fd102cc..00fa1a5455 100644
--- a/src/librustc/ty/fold.rs
+++ b/src/librustc/ty/fold.rs
@@ -243,10 +243,30 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
243 where F: FnMut(ty::Region<'tcx>), 243 where F: FnMut(ty::Region<'tcx>),
244 T: TypeFoldable<'tcx>, 244 T: TypeFoldable<'tcx>,
245 { 245 {
246 value.visit_with(&mut RegionVisitor { current_depth: 0, callback }); 246 value.visit_with(&mut RegionVisitor {
247 outer_index: ty::DebruijnIndex::INNERMOST,
248 callback
249 });
247 250
248 struct RegionVisitor<F> { 251 struct RegionVisitor<F> {
249 current_depth: u32, 252 /// The index of a binder *just outside* the things we have
253 /// traversed. If we encounter a bound region bound by this
254 /// binder or one outer to it, it appears free. Example:
255 ///
256 /// ```
257 /// for<'a> fn(for<'b> fn(), T)
258 /// ^ ^ ^ ^
259 /// | | | | here, would be shifted in 1
260 /// | | | here, would be shifted in 2
261 /// | | here, would be INNTERMOST shifted in by 1
262 /// | here, initially, binder would be INNERMOST
263 /// ```
264 ///
265 /// You see that, initially, *any* bound value is free,
266 /// because we've not traversed any binders. As we pass
267 /// through a binder, we shift the `outer_index` by 1 to
268 /// account for the new binder that encloses us.
269 outer_index: ty::DebruijnIndex,
250 callback: F, 270 callback: F,
251 } 271 }
252 272
@@ -254,16 +274,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
254 where F : FnMut(ty::Region<'tcx>) 274 where F : FnMut(ty::Region<'tcx>)
255 { 275 {
256 fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool { 276 fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
257 self.current_depth += 1; 277 self.outer_index.shift_in(1);
258 t.skip_binder().visit_with(self); 278 t.skip_binder().visit_with(self);
259 self.current_depth -= 1; 279 self.outer_index.shift_out(1);
260 280
261 false // keep visiting 281 false // keep visiting
262 } 282 }
263 283
264 fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool { 284 fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
265 match *r { 285 match *r {
266 ty::ReLateBound(debruijn, _) if debruijn.depth <= self.current_depth => { 286 ty::ReLateBound(debruijn, _) if debruijn < self.outer_index => {
267 /* ignore bound regions */ 287 /* ignore bound regions */
268 } 288 }
269 _ => (self.callback)(r), 289 _ => (self.callback)(r),