about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2022-07-29 22:38:07 -0300
committerSantiago Pastorino <spastorino@gmail.com>2022-08-04 11:26:54 -0300
commit4f334f2b970c3149365d4d98f02090d52767e44f (patch)
tree2b29f0853ac52ffd19f8d908964816bf22425600
parent9f77688d1707dc6108803a3e1c4a6aa2747568a4 (diff)
downloadrust-4f334f2b970c3149365d4d98f02090d52767e44f.tar.gz
rust-4f334f2b970c3149365d4d98f02090d52767e44f.zip
Move LifetimeCollectVisitor to rustc_ast_lowering
-rw-r--r--compiler/rustc_ast/src/ast.rs59
-rw-r--r--compiler/rustc_ast_lowering/src/lib.rs7
-rw-r--r--compiler/rustc_ast_lowering/src/lifetime_collector.rs62
3 files changed, 67 insertions, 61 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index 3503e5de8cc..870a7c0be33 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -25,9 +25,7 @@ pub use UnsafeSource::*;
 use crate::ptr::P;
 use crate::token::{self, CommentKind, Delimiter};
 use crate::tokenstream::{DelimSpan, LazyTokenStream, TokenStream};
-use crate::visit::{self, BoundKind, LifetimeCtxt, Visitor};
 
-use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_data_structures::stack::ensure_sufficient_stack;
 use rustc_data_structures::sync::Lrc;
@@ -325,63 +323,6 @@ impl GenericBound {
 
 pub type GenericBounds = Vec<GenericBound>;
 
-struct LifetimeCollectVisitor<'ast> {
-    current_binders: Vec<NodeId>,
-    binders_to_ignore: FxHashMap<NodeId, Vec<NodeId>>,
-    collected_lifetimes: Vec<&'ast Lifetime>,
-}
-
-impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
-    fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, _: LifetimeCtxt) {
-        if !self.collected_lifetimes.contains(&lifetime) {
-            self.collected_lifetimes.push(lifetime);
-        }
-        self.binders_to_ignore.insert(lifetime.id, self.current_binders.clone());
-    }
-
-    fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef, m: &'ast TraitBoundModifier) {
-        self.current_binders.push(t.trait_ref.ref_id);
-
-        visit::walk_poly_trait_ref(self, t, m);
-
-        self.current_binders.pop();
-    }
-
-    fn visit_ty(&mut self, t: &'ast Ty) {
-        if let TyKind::BareFn(_) = t.kind {
-            self.current_binders.push(t.id);
-        }
-        visit::walk_ty(self, t);
-        if let TyKind::BareFn(_) = t.kind {
-            self.current_binders.pop();
-        }
-    }
-}
-
-pub fn lifetimes_in_ret_ty(ret_ty: &FnRetTy) -> (Vec<&Lifetime>, FxHashMap<NodeId, Vec<NodeId>>) {
-    let mut visitor = LifetimeCollectVisitor {
-        current_binders: Vec::new(),
-        binders_to_ignore: FxHashMap::default(),
-        collected_lifetimes: Vec::new(),
-    };
-    visitor.visit_fn_ret_ty(ret_ty);
-    (visitor.collected_lifetimes, visitor.binders_to_ignore)
-}
-
-pub fn lifetimes_in_bounds(
-    bounds: &GenericBounds,
-) -> (Vec<&Lifetime>, FxHashMap<NodeId, Vec<NodeId>>) {
-    let mut visitor = LifetimeCollectVisitor {
-        current_binders: Vec::new(),
-        binders_to_ignore: FxHashMap::default(),
-        collected_lifetimes: Vec::new(),
-    };
-    for bound in bounds {
-        visitor.visit_param_bound(bound, BoundKind::Bound);
-    }
-    (visitor.collected_lifetimes, visitor.binders_to_ignore)
-}
-
 /// Specifies the enforced ordering for generic parameters. In the future,
 /// if we wanted to relax this order, we could override `PartialEq` and
 /// `PartialOrd`, to allow the kinds to be unordered.
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index 4ca771bf473..2883299291e 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -77,6 +77,7 @@ mod block;
 mod expr;
 mod index;
 mod item;
+mod lifetime_collector;
 mod pat;
 mod path;
 
@@ -1352,7 +1353,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                     }),
                 );
 
-                let (lifetimes_in_bounds, binders_to_ignore) = ast::lifetimes_in_bounds(bounds);
+                let (lifetimes_in_bounds, binders_to_ignore) =
+                    lifetime_collector::lifetimes_in_bounds(bounds);
                 debug!(?lifetimes_in_bounds);
                 debug!(?binders_to_ignore);
 
@@ -1756,7 +1758,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                 }),
             );
 
-            let (lifetimes_in_bounds, binders_to_ignore) = ast::lifetimes_in_ret_ty(output);
+            let (lifetimes_in_bounds, binders_to_ignore) =
+                lifetime_collector::lifetimes_in_ret_ty(output);
             debug!(?lifetimes_in_bounds);
             debug!(?binders_to_ignore);
 
diff --git a/compiler/rustc_ast_lowering/src/lifetime_collector.rs b/compiler/rustc_ast_lowering/src/lifetime_collector.rs
new file mode 100644
index 00000000000..1dab8799ae5
--- /dev/null
+++ b/compiler/rustc_ast_lowering/src/lifetime_collector.rs
@@ -0,0 +1,62 @@
+use rustc_ast::visit::{self, BoundKind, LifetimeCtxt, Visitor};
+use rustc_ast::{
+    FnRetTy, GenericBounds, Lifetime, NodeId, PolyTraitRef, TraitBoundModifier, Ty, TyKind,
+};
+use rustc_data_structures::fx::FxHashMap;
+
+struct LifetimeCollectVisitor<'ast> {
+    current_binders: Vec<NodeId>,
+    binders_to_ignore: FxHashMap<NodeId, Vec<NodeId>>,
+    collected_lifetimes: Vec<&'ast Lifetime>,
+}
+
+impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
+    fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, _: LifetimeCtxt) {
+        if !self.collected_lifetimes.contains(&lifetime) {
+            self.collected_lifetimes.push(lifetime);
+        }
+        self.binders_to_ignore.insert(lifetime.id, self.current_binders.clone());
+    }
+
+    fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef, m: &'ast TraitBoundModifier) {
+        self.current_binders.push(t.trait_ref.ref_id);
+
+        visit::walk_poly_trait_ref(self, t, m);
+
+        self.current_binders.pop();
+    }
+
+    fn visit_ty(&mut self, t: &'ast Ty) {
+        if let TyKind::BareFn(_) = t.kind {
+            self.current_binders.push(t.id);
+        }
+        visit::walk_ty(self, t);
+        if let TyKind::BareFn(_) = t.kind {
+            self.current_binders.pop();
+        }
+    }
+}
+
+pub fn lifetimes_in_ret_ty(ret_ty: &FnRetTy) -> (Vec<&Lifetime>, FxHashMap<NodeId, Vec<NodeId>>) {
+    let mut visitor = LifetimeCollectVisitor {
+        current_binders: Vec::new(),
+        binders_to_ignore: FxHashMap::default(),
+        collected_lifetimes: Vec::new(),
+    };
+    visitor.visit_fn_ret_ty(ret_ty);
+    (visitor.collected_lifetimes, visitor.binders_to_ignore)
+}
+
+pub fn lifetimes_in_bounds(
+    bounds: &GenericBounds,
+) -> (Vec<&Lifetime>, FxHashMap<NodeId, Vec<NodeId>>) {
+    let mut visitor = LifetimeCollectVisitor {
+        current_binders: Vec::new(),
+        binders_to_ignore: FxHashMap::default(),
+        collected_lifetimes: Vec::new(),
+    };
+    for bound in bounds {
+        visitor.visit_param_bound(bound, BoundKind::Bound);
+    }
+    (visitor.collected_lifetimes, visitor.binders_to_ignore)
+}