Make WalkItemKind::walk signature compatible between Visitor versions

This commit is contained in:
maxcabrajac 2024-11-12 13:20:17 -03:00
parent 6180173612
commit 516a3b0c9b
2 changed files with 27 additions and 18 deletions

View File

@ -112,11 +112,14 @@ pub enum LifetimeCtxt {
GenericArg, GenericArg,
} }
pub trait WalkItemKind: Sized { pub trait WalkItemKind {
type Ctxt; type Ctxt;
fn walk<'a, V: Visitor<'a>>( fn walk<'a, V: Visitor<'a>>(
&'a self, &'a self,
item: &'a Item<Self>, span: Span,
id: NodeId,
ident: &'a Ident,
visibility: &'a Visibility,
ctxt: Self::Ctxt, ctxt: Self::Ctxt,
visitor: &mut V, visitor: &mut V,
) -> V::Result; ) -> V::Result;
@ -341,14 +344,16 @@ impl WalkItemKind for ItemKind {
type Ctxt = (); type Ctxt = ();
fn walk<'a, V: Visitor<'a>>( fn walk<'a, V: Visitor<'a>>(
&'a self, &'a self,
item: &'a Item<Self>, span: Span,
id: NodeId,
ident: &'a Ident,
vis: &'a Visibility,
_ctxt: Self::Ctxt, _ctxt: Self::Ctxt,
visitor: &mut V, visitor: &mut V,
) -> V::Result { ) -> V::Result {
let Item { id, span, vis, ident, .. } = item;
match self { match self {
ItemKind::ExternCrate(_rename) => {} ItemKind::ExternCrate(_rename) => {}
ItemKind::Use(use_tree) => try_visit!(visitor.visit_use_tree(use_tree, *id, false)), ItemKind::Use(use_tree) => try_visit!(visitor.visit_use_tree(use_tree, id, false)),
ItemKind::Static(box StaticItem { ty, safety: _, mutability: _, expr }) => { ItemKind::Static(box StaticItem { ty, safety: _, mutability: _, expr }) => {
try_visit!(visitor.visit_ty(ty)); try_visit!(visitor.visit_ty(ty));
visit_opt!(visitor, visit_expr, expr); visit_opt!(visitor, visit_expr, expr);
@ -360,7 +365,7 @@ impl WalkItemKind for ItemKind {
} }
ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => { ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind = FnKind::Fn(FnCtxt::Free, ident, sig, vis, generics, body); let kind = FnKind::Fn(FnCtxt::Free, ident, sig, vis, generics, body);
try_visit!(visitor.visit_fn(kind, *span, *id)); try_visit!(visitor.visit_fn(kind, span, id));
} }
ItemKind::Mod(_unsafety, mod_kind) => match mod_kind { ItemKind::Mod(_unsafety, mod_kind) => match mod_kind {
ModKind::Loaded(items, _inline, _inner_span) => { ModKind::Loaded(items, _inline, _inner_span) => {
@ -417,7 +422,7 @@ impl WalkItemKind for ItemKind {
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
} }
ItemKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)), ItemKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
ItemKind::MacroDef(ts) => try_visit!(visitor.visit_mac_def(ts, *id)), ItemKind::MacroDef(ts) => try_visit!(visitor.visit_mac_def(ts, id)),
ItemKind::Delegation(box Delegation { ItemKind::Delegation(box Delegation {
id, id,
qself, qself,
@ -433,7 +438,7 @@ impl WalkItemKind for ItemKind {
} }
ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => { ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
try_visit!(walk_qself(visitor, qself)); try_visit!(walk_qself(visitor, qself));
try_visit!(visitor.visit_path(prefix, *id)); try_visit!(visitor.visit_path(prefix, id));
if let Some(suffixes) = suffixes { if let Some(suffixes) = suffixes {
for (ident, rename) in suffixes { for (ident, rename) in suffixes {
visitor.visit_ident(ident); visitor.visit_ident(ident);
@ -686,11 +691,13 @@ impl WalkItemKind for ForeignItemKind {
type Ctxt = (); type Ctxt = ();
fn walk<'a, V: Visitor<'a>>( fn walk<'a, V: Visitor<'a>>(
&'a self, &'a self,
item: &'a Item<Self>, span: Span,
id: NodeId,
ident: &'a Ident,
vis: &'a Visibility,
_ctxt: Self::Ctxt, _ctxt: Self::Ctxt,
visitor: &mut V, visitor: &mut V,
) -> V::Result { ) -> V::Result {
let Item { id, span, ident, vis, .. } = item;
match self { match self {
ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => { ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
try_visit!(visitor.visit_ty(ty)); try_visit!(visitor.visit_ty(ty));
@ -698,7 +705,7 @@ impl WalkItemKind for ForeignItemKind {
} }
ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => { ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body); let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body);
try_visit!(visitor.visit_fn(kind, *span, *id)); try_visit!(visitor.visit_fn(kind, span, id));
} }
ForeignItemKind::TyAlias(box TyAlias { ForeignItemKind::TyAlias(box TyAlias {
generics, generics,
@ -850,11 +857,13 @@ impl WalkItemKind for AssocItemKind {
type Ctxt = AssocCtxt; type Ctxt = AssocCtxt;
fn walk<'a, V: Visitor<'a>>( fn walk<'a, V: Visitor<'a>>(
&'a self, &'a self,
item: &'a Item<Self>, span: Span,
id: NodeId,
ident: &'a Ident,
vis: &'a Visibility,
ctxt: Self::Ctxt, ctxt: Self::Ctxt,
visitor: &mut V, visitor: &mut V,
) -> V::Result { ) -> V::Result {
let Item { id, span, ident, vis, .. } = item;
match self { match self {
AssocItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => { AssocItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
try_visit!(visitor.visit_generics(generics)); try_visit!(visitor.visit_generics(generics));
@ -863,7 +872,7 @@ impl WalkItemKind for AssocItemKind {
} }
AssocItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => { AssocItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body); let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body);
try_visit!(visitor.visit_fn(kind, *span, *id)); try_visit!(visitor.visit_fn(kind, span, id));
} }
AssocItemKind::Type(box TyAlias { AssocItemKind::Type(box TyAlias {
generics, generics,
@ -894,7 +903,7 @@ impl WalkItemKind for AssocItemKind {
} }
AssocItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => { AssocItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
try_visit!(walk_qself(visitor, qself)); try_visit!(walk_qself(visitor, qself));
try_visit!(visitor.visit_path(prefix, *id)); try_visit!(visitor.visit_path(prefix, id));
if let Some(suffixes) = suffixes { if let Some(suffixes) = suffixes {
for (ident, rename) in suffixes { for (ident, rename) in suffixes {
visitor.visit_ident(ident); visitor.visit_ident(ident);
@ -915,11 +924,11 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>, K: WalkItemKind>(
item: &'a Item<K>, item: &'a Item<K>,
ctxt: K::Ctxt, ctxt: K::Ctxt,
) -> V::Result { ) -> V::Result {
let Item { id: _, span: _, ident, vis, attrs, kind, tokens: _ } = item; let Item { id, span, ident, vis, attrs, kind, tokens: _ } = item;
walk_list!(visitor, visit_attribute, attrs); walk_list!(visitor, visit_attribute, attrs);
try_visit!(visitor.visit_vis(vis)); try_visit!(visitor.visit_vis(vis));
try_visit!(visitor.visit_ident(ident)); try_visit!(visitor.visit_ident(ident));
try_visit!(kind.walk(item, ctxt, visitor)); try_visit!(kind.walk(*span, *id, ident, vis, ctxt, visitor));
V::Result::output() V::Result::output()
} }

View File

@ -1324,7 +1324,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
// This way they can use `macro_rules` defined later. // This way they can use `macro_rules` defined later.
self.visit_vis(&item.vis); self.visit_vis(&item.vis);
self.visit_ident(&item.ident); self.visit_ident(&item.ident);
item.kind.walk(item, (), self); item.kind.walk(item.span, item.id, &item.ident, &item.vis, (), self);
visit::walk_list!(self, visit_attribute, &item.attrs); visit::walk_list!(self, visit_attribute, &item.attrs);
} }
_ => visit::walk_item(self, item), _ => visit::walk_item(self, item),