Skip to content

Commit 8f15d1e

Browse files
nikomatsakiscsmoe
andcommitted
replace binder_depth in LateBoundRegionsDetector
Co-authored-by: csmoe <[email protected]>
1 parent 06b2a3f commit 8f15d1e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/librustc_typeck/collect.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
689689
-> Option<Span> {
690690
struct LateBoundRegionsDetector<'a, 'tcx: 'a> {
691691
tcx: TyCtxt<'a, 'tcx, 'tcx>,
692-
binder_depth: u32,
692+
outer_index: ty::DebruijnIndex,
693693
has_late_bound_regions: Option<Span>,
694694
}
695695

@@ -702,9 +702,9 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
702702
if self.has_late_bound_regions.is_some() { return }
703703
match ty.node {
704704
hir::TyBareFn(..) => {
705-
self.binder_depth += 1;
705+
self.outer_index.shift_in(1);
706706
intravisit::walk_ty(self, ty);
707-
self.binder_depth -= 1;
707+
self.outer_index.shift_out(1);
708708
}
709709
_ => intravisit::walk_ty(self, ty)
710710
}
@@ -714,9 +714,9 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
714714
tr: &'tcx hir::PolyTraitRef,
715715
m: hir::TraitBoundModifier) {
716716
if self.has_late_bound_regions.is_some() { return }
717-
self.binder_depth += 1;
717+
self.outer_index.shift_in(1);
718718
intravisit::walk_poly_trait_ref(self, tr, m);
719-
self.binder_depth -= 1;
719+
self.outer_index.shift_out(1);
720720
}
721721

722722
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>,
727727
Some(rl::Region::Static) | Some(rl::Region::EarlyBound(..)) => {}
728728
Some(rl::Region::LateBound(debruijn, _, _)) |
729729
Some(rl::Region::LateBoundAnon(debruijn, _))
730-
if debruijn.depth < self.binder_depth => {}
731-
_ => self.has_late_bound_regions = Some(lt.span),
730+
if debruijn < self.outer_index => {}
731+
Some(rl::Region::LateBound(..)) |
732+
Some(rl::Region::LateBoundAnon(..)) |
733+
Some(rl::Region::Free(..)) |
734+
None => {
735+
self.has_late_bound_regions = Some(lt.span);
736+
}
732737
}
733738
}
734739
}
@@ -738,7 +743,9 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
738743
decl: &'tcx hir::FnDecl)
739744
-> Option<Span> {
740745
let mut visitor = LateBoundRegionsDetector {
741-
tcx, binder_depth: 1, has_late_bound_regions: None
746+
tcx,
747+
outer_index: ty::DebruijnIndex::INNERMOST,
748+
has_late_bound_regions: None,
742749
};
743750
for lifetime in generics.lifetimes() {
744751
let hir_id = tcx.hir.node_to_hir_id(lifetime.lifetime.id);

0 commit comments

Comments
 (0)