Skip to content

Commit

Permalink
replace binder_depth in LateBoundRegionsDetector
Browse files Browse the repository at this point in the history
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
  • Loading branch information
nikomatsakis and csmoe committed May 28, 2018
1 parent 06b2a3f commit 8f15d1e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/librustc_typeck/collect.rs
Expand Up @@ -689,7 +689,7 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
-> Option<Span> {
struct LateBoundRegionsDetector<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
binder_depth: u32,
outer_index: ty::DebruijnIndex,
has_late_bound_regions: Option<Span>,
}

Expand All @@ -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)
}
Expand All @@ -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) {
Expand All @@ -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);
}
}
}
}
Expand All @@ -738,7 +743,9 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
decl: &'tcx hir::FnDecl)
-> Option<Span> {
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);
Expand Down

0 comments on commit 8f15d1e

Please sign in to comment.