summary refs log tree commit diff
path: root/compiler/rustc_ast
diff options
context:
space:
mode:
authormaxcabrajac <max@cabrajac.com>2024-11-08 18:51:28 -0300
committermaxcabrajac <max@cabrajac.com>2024-11-15 17:00:01 -0300
commit6180173612e7a8de35db441cde14c3cfacc62af7 (patch)
treeaf955a5727c5b619327e8f83679d327b35fe243d /compiler/rustc_ast
parent12366563196d02f411d6743c0f41284837dc3f4c (diff)
downloadrust-6180173612e7a8de35db441cde14c3cfacc62af7.tar.gz
rust-6180173612e7a8de35db441cde14c3cfacc62af7.zip
Add WalkItemKind::Ctxt so AssocCtxt is not sent to non-Assoc ItemKinds
Diffstat (limited to 'compiler/rustc_ast')
-rw-r--r--compiler/rustc_ast/src/mut_visit.rs24
-rw-r--r--compiler/rustc_ast/src/visit.rs22
2 files changed, 27 insertions, 19 deletions
diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs
index fe5ec1e5ad3..a09aa9ee665 100644
--- a/compiler/rustc_ast/src/mut_visit.rs
+++ b/compiler/rustc_ast/src/mut_visit.rs
@@ -37,13 +37,14 @@ impl<A: Array> ExpectOne<A> for SmallVec<A> {
 }
 
 pub trait WalkItemKind {
+    type Ctxt;
     fn walk(
         &mut self,
         span: Span,
         id: NodeId,
         ident: &mut Ident,
         visibility: &mut Visibility,
-        ctxt: AssocCtxt,
+        ctxt: Self::Ctxt,
         visitor: &mut impl MutVisitor,
     );
 }
@@ -1088,26 +1089,27 @@ pub fn walk_block<T: MutVisitor>(vis: &mut T, block: &mut P<Block>) {
     vis.visit_span(span);
 }
 
-pub fn walk_item_kind(
-    kind: &mut impl WalkItemKind,
+pub fn walk_item_kind<K: WalkItemKind>(
+    kind: &mut K,
     span: Span,
     id: NodeId,
     ident: &mut Ident,
     visibility: &mut Visibility,
-    ctxt: AssocCtxt,
+    ctxt: K::Ctxt,
     vis: &mut impl MutVisitor,
 ) {
     kind.walk(span, id, ident, visibility, ctxt, vis)
 }
 
 impl WalkItemKind for ItemKind {
+    type Ctxt = ();
     fn walk(
         &mut self,
         span: Span,
         id: NodeId,
         ident: &mut Ident,
         visibility: &mut Visibility,
-        _ctxt: AssocCtxt,
+        _ctxt: Self::Ctxt,
         vis: &mut impl MutVisitor,
     ) {
         match self {
@@ -1225,13 +1227,14 @@ impl WalkItemKind for ItemKind {
 }
 
 impl WalkItemKind for AssocItemKind {
+    type Ctxt = AssocCtxt;
     fn walk(
         &mut self,
         span: Span,
         id: NodeId,
         ident: &mut Ident,
         visibility: &mut Visibility,
-        ctxt: AssocCtxt,
+        ctxt: Self::Ctxt,
         visitor: &mut impl MutVisitor,
     ) {
         match self {
@@ -1324,17 +1327,17 @@ pub fn walk_crate<T: MutVisitor>(vis: &mut T, krate: &mut Crate) {
     vis.visit_span(inject_use_span);
 }
 
-pub fn walk_flat_map_item<K: WalkItemKind>(
+pub fn walk_flat_map_item<K: WalkItemKind<Ctxt = ()>>(
     visitor: &mut impl MutVisitor,
     item: P<Item<K>>,
 ) -> SmallVec<[P<Item<K>>; 1]> {
-    walk_flat_map_assoc_item(visitor, item, AssocCtxt::Trait /* ignored */)
+    walk_flat_map_assoc_item(visitor, item, ())
 }
 
 pub fn walk_flat_map_assoc_item<K: WalkItemKind>(
     visitor: &mut impl MutVisitor,
     mut item: P<Item<K>>,
-    ctxt: AssocCtxt,
+    ctxt: K::Ctxt,
 ) -> SmallVec<[P<Item<K>>; 1]> {
     let Item { ident, attrs, id, kind, vis, span, tokens } = item.deref_mut();
     visitor.visit_id(id);
@@ -1348,13 +1351,14 @@ pub fn walk_flat_map_assoc_item<K: WalkItemKind>(
 }
 
 impl WalkItemKind for ForeignItemKind {
+    type Ctxt = ();
     fn walk(
         &mut self,
         span: Span,
         id: NodeId,
         ident: &mut Ident,
         visibility: &mut Visibility,
-        _ctxt: AssocCtxt,
+        _ctxt: Self::Ctxt,
         visitor: &mut impl MutVisitor,
     ) {
         match self {
diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs
index 01c7a815e00..243a000e916 100644
--- a/compiler/rustc_ast/src/visit.rs
+++ b/compiler/rustc_ast/src/visit.rs
@@ -113,10 +113,11 @@ pub enum LifetimeCtxt {
 }
 
 pub trait WalkItemKind: Sized {
+    type Ctxt;
     fn walk<'a, V: Visitor<'a>>(
         &'a self,
         item: &'a Item<Self>,
-        ctxt: AssocCtxt,
+        ctxt: Self::Ctxt,
         visitor: &mut V,
     ) -> V::Result;
 }
@@ -337,10 +338,11 @@ pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitR
 }
 
 impl WalkItemKind for ItemKind {
+    type Ctxt = ();
     fn walk<'a, V: Visitor<'a>>(
         &'a self,
         item: &'a Item<Self>,
-        _ctxt: AssocCtxt,
+        _ctxt: Self::Ctxt,
         visitor: &mut V,
     ) -> V::Result {
         let Item { id, span, vis, ident, .. } = item;
@@ -449,9 +451,9 @@ impl WalkItemKind for ItemKind {
 
 pub fn walk_item<'a, V: Visitor<'a>>(
     visitor: &mut V,
-    item: &'a Item<impl WalkItemKind>,
+    item: &'a Item<impl WalkItemKind<Ctxt = ()>>,
 ) -> V::Result {
-    walk_assoc_item(visitor, item, AssocCtxt::Trait /*ignored*/)
+    walk_assoc_item(visitor, item, ())
 }
 
 pub fn walk_enum_def<'a, V: Visitor<'a>>(
@@ -681,10 +683,11 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Res
 }
 
 impl WalkItemKind for ForeignItemKind {
+    type Ctxt = ();
     fn walk<'a, V: Visitor<'a>>(
         &'a self,
         item: &'a Item<Self>,
-        _ctxt: AssocCtxt,
+        _ctxt: Self::Ctxt,
         visitor: &mut V,
     ) -> V::Result {
         let Item { id, span, ident, vis, .. } = item;
@@ -844,10 +847,11 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
 }
 
 impl WalkItemKind for AssocItemKind {
+    type Ctxt = AssocCtxt;
     fn walk<'a, V: Visitor<'a>>(
         &'a self,
         item: &'a Item<Self>,
-        ctxt: AssocCtxt,
+        ctxt: Self::Ctxt,
         visitor: &mut V,
     ) -> V::Result {
         let Item { id, span, ident, vis, .. } = item;
@@ -906,10 +910,10 @@ impl WalkItemKind for AssocItemKind {
     }
 }
 
-pub fn walk_assoc_item<'a, V: Visitor<'a>>(
+pub fn walk_assoc_item<'a, V: Visitor<'a>, K: WalkItemKind>(
     visitor: &mut V,
-    item: &'a Item<impl WalkItemKind>,
-    ctxt: AssocCtxt,
+    item: &'a Item<K>,
+    ctxt: K::Ctxt,
 ) -> V::Result {
     let Item { id: _, span: _, ident, vis, attrs, kind, tokens: _ } = item;
     walk_list!(visitor, visit_attribute, attrs);