From 8f15d1ea255a8d0bddd6194aefe5cfee0434e0a1 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 28 May 2018 10:43:54 -0400 Subject: [PATCH] replace `binder_depth` in `LateBoundRegionsDetector` Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com> --- src/librustc_typeck/collect.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index d0c67c2882cff..a982724f957e9 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -689,7 +689,7 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, -> Option { struct LateBoundRegionsDetector<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, - binder_depth: u32, + outer_index: ty::DebruijnIndex, has_late_bound_regions: Option, } @@ -702,9 +702,9 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if self.has_late_bound_regions.is_some() { return } match ty.node { hir::TyBareFn(..) => { - self.binder_depth += 1; + self.outer_index.shift_in(1); intravisit::walk_ty(self, ty); - self.binder_depth -= 1; + self.outer_index.shift_out(1); } _ => intravisit::walk_ty(self, ty) } @@ -714,9 +714,9 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tr: &'tcx hir::PolyTraitRef, m: hir::TraitBoundModifier) { if self.has_late_bound_regions.is_some() { return } - self.binder_depth += 1; + self.outer_index.shift_in(1); intravisit::walk_poly_trait_ref(self, tr, m); - self.binder_depth -= 1; + self.outer_index.shift_out(1); } fn visit_lifetime(&mut self, lt: &'tcx hir::Lifetime) { @@ -727,8 +727,13 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, Some(rl::Region::Static) | Some(rl::Region::EarlyBound(..)) => {} Some(rl::Region::LateBound(debruijn, _, _)) | Some(rl::Region::LateBoundAnon(debruijn, _)) - if debruijn.depth < self.binder_depth => {} - _ => self.has_late_bound_regions = Some(lt.span), + if debruijn < self.outer_index => {} + Some(rl::Region::LateBound(..)) | + Some(rl::Region::LateBoundAnon(..)) | + Some(rl::Region::Free(..)) | + None => { + self.has_late_bound_regions = Some(lt.span); + } } } } @@ -738,7 +743,9 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, decl: &'tcx hir::FnDecl) -> Option { let mut visitor = LateBoundRegionsDetector { - tcx, binder_depth: 1, has_late_bound_regions: None + tcx, + outer_index: ty::DebruijnIndex::INNERMOST, + has_late_bound_regions: None, }; for lifetime in generics.lifetimes() { let hir_id = tcx.hir.node_to_hir_id(lifetime.lifetime.id);