summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-05-28 10:43:54 -0400
committerNiko Matsakis <niko@alum.mit.edu>2018-05-28 19:47:04 -0400
commit8f15d1ea255a8d0bddd6194aefe5cfee0434e0a1 (patch)
tree57a6b775bc772c22b980e684298c41167910beb8 /src
parentconvert `LateBoundRegionsCollector` to track a debruijn index (diff)
downloadgrust-8f15d1ea255a8d0bddd6194aefe5cfee0434e0a1.tar.gz
grust-8f15d1ea255a8d0bddd6194aefe5cfee0434e0a1.tar.bz2
grust-8f15d1ea255a8d0bddd6194aefe5cfee0434e0a1.tar.xz
replace `binder_depth` in `LateBoundRegionsDetector`
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/collect.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index d0c67c2882..a982724f95 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>,
689 -> Option<Span> { 689 -> Option<Span> {
690 struct LateBoundRegionsDetector<'a, 'tcx: 'a> { 690 struct LateBoundRegionsDetector<'a, 'tcx: 'a> {
691 tcx: TyCtxt<'a, 'tcx, 'tcx>, 691 tcx: TyCtxt<'a, 'tcx, 'tcx>,
692 binder_depth: u32, 692 outer_index: ty::DebruijnIndex,
693 has_late_bound_regions: Option<Span>, 693 has_late_bound_regions: Option<Span>,
694 } 694 }
695 695
@@ -702,9 +702,9 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
702 if self.has_late_bound_regions.is_some() { return } 702 if self.has_late_bound_regions.is_some() { return }
703 match ty.node { 703 match ty.node {
704 hir::TyBareFn(..) => { 704 hir::TyBareFn(..) => {
705 self.binder_depth += 1; 705 self.outer_index.shift_in(1);
706 intravisit::walk_ty(self, ty); 706 intravisit::walk_ty(self, ty);
707 self.binder_depth -= 1; 707 self.outer_index.shift_out(1);
708 } 708 }
709 _ => intravisit::walk_ty(self, ty) 709 _ => intravisit::walk_ty(self, ty)
710 } 710 }
@@ -714,9 +714,9 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
714 tr: &'tcx hir::PolyTraitRef, 714 tr: &'tcx hir::PolyTraitRef,
715 m: hir::TraitBoundModifier) { 715 m: hir::TraitBoundModifier) {
716 if self.has_late_bound_regions.is_some() { return } 716 if self.has_late_bound_regions.is_some() { return }
717 self.binder_depth += 1; 717 self.outer_index.shift_in(1);
718 intravisit::walk_poly_trait_ref(self, tr, m); 718 intravisit::walk_poly_trait_ref(self, tr, m);
719 self.binder_depth -= 1; 719 self.outer_index.shift_out(1);
720 } 720 }
721 721
722 fn visit_lifetime(&mut self, lt: &'tcx hir::Lifetime) { 722 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>,
727 Some(rl::Region::Static) | Some(rl::Region::EarlyBound(..)) => {} 727 Some(rl::Region::Static) | Some(rl::Region::EarlyBound(..)) => {}
728 Some(rl::Region::LateBound(debruijn, _, _)) | 728 Some(rl::Region::LateBound(debruijn, _, _)) |
729 Some(rl::Region::LateBoundAnon(debruijn, _)) 729 Some(rl::Region::LateBoundAnon(debruijn, _))
730 if debruijn.depth < self.binder_depth => {} 730 if debruijn < self.outer_index => {}
731 _ => self.has_late_bound_regions = Some(lt.span), 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 }
732 } 737 }
733 } 738 }
734 } 739 }
@@ -738,7 +743,9 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
738 decl: &'tcx hir::FnDecl) 743 decl: &'tcx hir::FnDecl)
739 -> Option<Span> { 744 -> Option<Span> {
740 let mut visitor = LateBoundRegionsDetector { 745 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,
742 }; 749 };
743 for lifetime in generics.lifetimes() { 750 for lifetime in generics.lifetimes() {
744 let hir_id = tcx.hir.node_to_hir_id(lifetime.lifetime.id); 751 let hir_id = tcx.hir.node_to_hir_id(lifetime.lifetime.id);