From 6180173612e7a8de35db441cde14c3cfacc62af7 Mon Sep 17 00:00:00 2001 From: maxcabrajac Date: Fri, 8 Nov 2024 18:51:28 -0300 Subject: Add WalkItemKind::Ctxt so AssocCtxt is not sent to non-Assoc ItemKinds --- compiler/rustc_ast/src/visit.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'compiler/rustc_ast/src/visit.rs') 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, - 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, - _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, + item: &'a Item>, ) -> 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, - _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, - 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, - ctxt: AssocCtxt, + item: &'a Item, + ctxt: K::Ctxt, ) -> V::Result { let Item { id: _, span: _, ident, vis, attrs, kind, tokens: _ } = item; walk_list!(visitor, visit_attribute, attrs); -- cgit 1.4.1-3-g733a5