Skip to content

Commit

Permalink
Unify {visit,walk}_macro_def
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcabrajac committed Oct 13, 2024
1 parent de7cf83 commit acfa04c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions compiler/rustc_ast/src/visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ macro_rules! make_ast_visitor {

make_visit!{CoroutineKind; visit_coroutine_kind, walk_coroutine_kind}
make_visit!{FnHeader; visit_fn_header, walk_fn_header}
make_visit!{MacroDef; visit_macro_def, walk_macro_def}
make_visit!{MetaItem; visit_meta_item, walk_meta_item}
make_visit!{MetaItemInner; visit_meta_list_item, walk_meta_list_item}

Expand Down Expand Up @@ -297,9 +296,6 @@ macro_rules! make_ast_visitor {
fn visit_fn(&mut self, fk: FnKind<'ast>, _: Span, _: NodeId) -> Self::Result {
walk_fn(self, fk)
}
fn visit_mac_def(&mut self, _mac: &'ast MacroDef, _id: NodeId) -> Self::Result {
Self::Result::output()
}
fn visit_fn_header(&mut self, _header: &'ast FnHeader) -> Self::Result {
Self::Result::output()
}
Expand Down Expand Up @@ -334,6 +330,7 @@ macro_rules! make_ast_visitor {
make_visit!{Lifetime, _ ctxt: LifetimeCtxt; visit_lifetime, walk_lifetime}
make_visit!{Local; visit_local, walk_local}
make_visit!{MacCall; visit_mac_call, walk_mac_call}
make_visit!{MacroDef, _ id: NodeId; visit_macro_def, walk_macro_def}
make_visit!{MutTy; visit_mt, walk_mt}
make_visit!{Option<P<QSelf>>; visit_qself, walk_qself}
make_visit!{Param; visit_param, walk_param}
Expand Down Expand Up @@ -813,6 +810,15 @@ macro_rules! make_ast_visitor {
return_result!(V)
}

pub fn walk_macro_def<$($lt,)? V: $trait$(<$lt>)?>(
vis: &mut V,
macro_def: ref_t!(MacroDef),
) -> result!(V) {
let MacroDef { body, macro_rules: _ } = macro_def;
visit_delim_args!(vis, body);
return_result!(V)
}

pub fn walk_mt<$($lt,)? V: $trait$(<$lt>)?>(
vis: &mut V,
mt: ref_t!(MutTy)
Expand Down Expand Up @@ -1388,7 +1394,7 @@ pub mod visit {
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
}
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_macro_def(ts, *id)),
ItemKind::Delegation(box Delegation {
id,
qself,
Expand Down Expand Up @@ -1872,11 +1878,6 @@ pub mod mut_visit {
smallvec![variant]
}

fn walk_macro_def<T: MutVisitor>(vis: &mut T, macro_def: &mut MacroDef) {
let MacroDef { body, macro_rules: _ } = macro_def;
visit_delim_args(vis, body);
}

fn walk_meta_list_item<T: MutVisitor>(vis: &mut T, li: &mut MetaItemInner) {
match li {
MetaItemInner::MetaItem(mi) => vis.visit_meta_item(mi),
Expand Down Expand Up @@ -2230,7 +2231,7 @@ pub mod mut_visit {
visit_bounds(vis, bounds, BoundKind::Bound);
}
ItemKind::MacCall(m) => vis.visit_mac_call(m),
ItemKind::MacroDef(def) => vis.visit_macro_def(def),
ItemKind::MacroDef(def) => vis.visit_macro_def(def, id),
ItemKind::Delegation(box Delegation {
id,
qself,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
lint_callback!(self, check_attribute, attr);
}

fn visit_mac_def(&mut self, mac: &'a ast::MacroDef, id: ast::NodeId) {
fn visit_macro_def(&mut self, mac: &'a ast::MacroDef, id: ast::NodeId) {
lint_callback!(self, check_mac_def, mac);
self.check_id(id);
}
Expand Down

0 comments on commit acfa04c

Please sign in to comment.