Skip to content

Commit

Permalink
Unify walk_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcabrajac committed Aug 28, 2024
1 parent 28e159e commit 6613670
Showing 1 changed file with 25 additions and 35 deletions.
60 changes: 25 additions & 35 deletions compiler/rustc_ast/src/visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,29 @@ macro_rules! make_ast_visitor {
return_result!(V)
}

pub fn walk_attribute<$($lt,)? V: $trait$(<$lt>)?>(
vis: &mut V,
attr: ref_t!(Attribute)
) -> result!(V) {
let Attribute { kind, id:_, style: _, span } = attr;
match kind {
AttrKind::Normal(normal) => {
let NormalAttr {
item: AttrItem { unsafety, path, args, tokens },
tokens: attr_tokens,
} = &$($mut)? **normal;
visit_safety!(vis, unsafety);
try_v!(vis.visit_path(path, DUMMY_NODE_ID));
try_v!(walk_attr_args(vis, args));
visit_lazy_tts!(vis, tokens);
visit_lazy_tts!(vis, attr_tokens);
}
AttrKind::DocComment(_kind, _sym) => {}
}
try_v!(visit_span!(vis, span));
return_result!(V)
}

pub fn walk_assoc_item<$($lt,)? V: $trait$(<$lt>)?>(
visitor: &mut V,
item: ref_t!(Item<AssocItemKind>),
Expand Down Expand Up @@ -1880,20 +1903,6 @@ pub mod visit {
visitor.visit_expr_post(expression)
}

pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) -> V::Result {
let Attribute { kind, id: _, style: _, span: _ } = attr;
match kind {
AttrKind::Normal(normal) => {
let NormalAttr { item, tokens: _ } = &**normal;
let AttrItem { unsafety: _, path, args, tokens: _ } = item;
try_visit!(visitor.visit_path(path, DUMMY_NODE_ID));
try_visit!(walk_attr_args(visitor, args));
}
AttrKind::DocComment(_kind, _sym) => {}
}
V::Result::output()
}

pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) -> V::Result {
match args {
AttrArgs::Empty => {}
Expand Down Expand Up @@ -2009,8 +2018,7 @@ pub mod mut_visit {
exprs.flat_map_in_place(|expr| vis.filter_map_expr(expr))
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
fn walk_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
match args {
AttrArgs::Empty => {}
AttrArgs::Delimited(args) => visit_delim_args(vis, args),
Expand All @@ -2036,24 +2044,6 @@ pub mod mut_visit {
vis.visit_span(close);
}

fn walk_attribute<T: MutVisitor>(vis: &mut T, attr: &mut Attribute) {
let Attribute { kind, id: _, style: _, span } = attr;
match kind {
AttrKind::Normal(normal) => {
let NormalAttr {
item: AttrItem { unsafety: _, path, args, tokens },
tokens: attr_tokens,
} = &mut **normal;
vis.visit_path(path, DUMMY_NODE_ID);
visit_attr_args(vis, args);
visit_lazy_tts(vis, tokens);
visit_lazy_tts(vis, attr_tokens);
}
AttrKind::DocComment(_kind, _sym) => {}
}
vis.visit_span(span);
}

fn walk_mac<T: MutVisitor>(vis: &mut T, mac: &mut MacCall) {
let MacCall { path, args } = mac;
vis.visit_path(path, DUMMY_NODE_ID);
Expand Down Expand Up @@ -2220,7 +2210,7 @@ pub mod mut_visit {
token::NtMeta(item) => {
let AttrItem { unsafety: _, path, args, tokens } = item.deref_mut();
vis.visit_path(path, DUMMY_NODE_ID);
visit_attr_args(vis, args);
walk_attr_args(vis, args);
visit_lazy_tts(vis, tokens);
}
token::NtPath(path) => vis.visit_path(path, DUMMY_NODE_ID),
Expand Down

0 comments on commit 6613670

Please sign in to comment.