Skip to content

Commit

Permalink
Factor out repeated visit_id calls.
Browse files Browse the repository at this point in the history
Every `ItemKind` now has one.
  • Loading branch information
nnethercote committed Mar 7, 2025
1 parent 872ac73 commit 8a98124
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,29 +532,25 @@ pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) ->
}

pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::Result {
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_ident(item.ident));
match item.kind {
ItemKind::ExternCrate(orig_name) => {
try_visit!(visitor.visit_id(item.hir_id()));
visit_opt!(visitor, visit_name, orig_name);
}
ItemKind::Use(ref path, _) => {
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_use(path, item.hir_id()));
}
ItemKind::Static(ref typ, _, body) => {
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_ty_unambig(typ));
try_visit!(visitor.visit_nested_body(body));
}
ItemKind::Const(ref typ, ref generics, body) => {
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_ty_unambig(typ));
try_visit!(visitor.visit_generics(generics));
try_visit!(visitor.visit_nested_body(body));
}
ItemKind::Fn { sig, generics, body: body_id, .. } => {
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_fn(
FnKind::ItemFn(item.ident, generics, sig.header),
sig.decl,
Expand All @@ -563,32 +559,25 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
item.owner_id.def_id,
));
}
ItemKind::Macro(..) => {
try_visit!(visitor.visit_id(item.hir_id()));
}
ItemKind::Macro(..) => {}
ItemKind::Mod(ref module) => {
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_mod(module, item.span, item.hir_id()));
}
ItemKind::ForeignMod { abi: _, items } => {
try_visit!(visitor.visit_id(item.hir_id()));
walk_list!(visitor, visit_foreign_item_ref, items);
}
ItemKind::GlobalAsm { asm: _, fake_body } => {
try_visit!(visitor.visit_id(item.hir_id()));
// Visit the fake body, which contains the asm statement.
// Therefore we should not visit the asm statement again
// outside of the body, or some visitors won't have their
// typeck results set correctly.
try_visit!(visitor.visit_nested_body(fake_body));
}
ItemKind::TyAlias(ref ty, ref generics) => {
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_ty_unambig(ty));
try_visit!(visitor.visit_generics(generics));
}
ItemKind::Enum(ref enum_definition, ref generics) => {
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_generics(generics));
try_visit!(visitor.visit_enum_def(enum_definition));
}
Expand All @@ -603,7 +592,6 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
self_ty,
items,
}) => {
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_generics(generics));
visit_opt!(visitor, visit_trait_ref, of_trait);
try_visit!(visitor.visit_ty_unambig(self_ty));
Expand All @@ -612,17 +600,14 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
ItemKind::Struct(ref struct_definition, ref generics)
| ItemKind::Union(ref struct_definition, ref generics) => {
try_visit!(visitor.visit_generics(generics));
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_variant_data(struct_definition));
}
ItemKind::Trait(.., ref generics, bounds, trait_item_refs) => {
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_generics(generics));
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
}
ItemKind::TraitAlias(ref generics, bounds) => {
try_visit!(visitor.visit_id(item.hir_id()));
try_visit!(visitor.visit_generics(generics));
walk_list!(visitor, visit_param_bound, bounds);
}
Expand Down

0 comments on commit 8a98124

Please sign in to comment.