Skip to content

Commit

Permalink
Use same naming convention on visit::walk_item
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcabrajac committed Nov 18, 2024
1 parent 436969e commit dfd9184
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 73 deletions.
15 changes: 4 additions & 11 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ pub trait Visitor<'ast>: Sized {
Self::Result::output()
}
fn visit_foreign_item(&mut self, i: &'ast ForeignItem) -> Self::Result {
walk_item(self, i)
walk_item(self, i, ())
}
fn visit_item(&mut self, i: &'ast Item) -> Self::Result {
walk_item(self, i)
walk_item(self, i, ())
}
fn visit_local(&mut self, l: &'ast Local) -> Self::Result {
walk_local(self, l)
Expand Down Expand Up @@ -196,7 +196,7 @@ pub trait Visitor<'ast>: Sized {
walk_fn(self, fk)
}
fn visit_assoc_item(&mut self, i: &'ast AssocItem, ctxt: AssocCtxt) -> Self::Result {
walk_assoc_item(self, i, ctxt)
walk_item(self, i, ctxt)
}
fn visit_trait_ref(&mut self, t: &'ast TraitRef) -> Self::Result {
walk_trait_ref(self, t)
Expand Down Expand Up @@ -457,13 +457,6 @@ impl WalkItemKind for ItemKind {
}
}

pub fn walk_item<'a, V: Visitor<'a>>(
visitor: &mut V,
item: &'a Item<impl WalkItemKind<Ctxt = ()>>,
) -> V::Result {
walk_assoc_item(visitor, item, ())
}

pub fn walk_enum_def<'a, V: Visitor<'a>>(
visitor: &mut V,
EnumDef { variants }: &'a EnumDef,
Expand Down Expand Up @@ -925,7 +918,7 @@ impl WalkItemKind for AssocItemKind {
}
}

pub fn walk_assoc_item<'a, V: Visitor<'a>, K: WalkItemKind>(
pub fn walk_item<'a, V: Visitor<'a>, K: WalkItemKind>(
visitor: &mut V,
item: &'a Item<K>,
ctxt: K::Ctxt,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,21 +379,21 @@ fn index_crate<'a>(
fn visit_item(&mut self, item: &'a ast::Item) {
let def_id = self.node_id_to_def_id[&item.id];
*self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner) = AstOwner::Item(item);
visit::walk_item(self, item)
visit::walk_item(self, item, ())
}

fn visit_assoc_item(&mut self, item: &'a ast::AssocItem, ctxt: visit::AssocCtxt) {
let def_id = self.node_id_to_def_id[&item.id];
*self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner) =
AstOwner::AssocItem(item, ctxt);
visit::walk_assoc_item(self, item, ctxt);
visit::walk_item(self, item, ctxt);
}

fn visit_foreign_item(&mut self, item: &'a ast::ForeignItem) {
let def_id = self.node_id_to_def_id[&item.id];
*self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner) =
AstOwner::ForeignItem(item);
visit::walk_item(self, item);
visit::walk_item(self, item, ());
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
if abi.is_none() {
this.maybe_lint_missing_abi(*extern_span, item.id);
}
visit::walk_item(this, item);
visit::walk_item(this, item, ());
this.extern_mod = old_item;
});
return; // Avoid visiting again.
Expand Down Expand Up @@ -1112,7 +1112,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
_ => {}
}

visit::walk_item(self, item);
visit::walk_item(self, item, ());
}

fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
Expand Down Expand Up @@ -1145,7 +1145,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
ForeignItemKind::MacCall(..) => {}
}

visit::walk_item(self, fi)
visit::walk_item(self, fi, ())
}

// Mirrors `visit::walk_generic_args`, but tracks relevant state.
Expand Down Expand Up @@ -1491,10 +1491,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
None => TildeConstReason::InherentAssocTy { span: item.span },
});
self.with_tilde_const(disallowed, |this| {
this.with_in_trait_impl(None, |this| visit::walk_assoc_item(this, item, ctxt))
this.with_in_trait_impl(None, |this| visit::walk_item(this, item, ctxt))
})
}
_ => self.with_in_trait_impl(None, |this| visit::walk_assoc_item(this, item, ctxt)),
_ => self.with_in_trait_impl(None, |this| visit::walk_item(this, item, ctxt)),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
_ => {}
}

visit::walk_item(self, i);
visit::walk_item(self, i, ());
}

fn visit_foreign_item(&mut self, i: &'a ast::ForeignItem) {
Expand All @@ -322,7 +322,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::ForeignItemKind::MacCall(..) => {}
}

visit::walk_item(self, i)
visit::walk_item(self, i, ())
}

fn visit_ty(&mut self, ty: &'a ast::Ty) {
Expand Down Expand Up @@ -477,7 +477,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
"specialization is unstable"
);
}
visit::walk_assoc_item(self, i, ctxt)
visit::walk_item(self, i, ctxt)
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_passes/src/node_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ impl<'ast> Visitor<'ast> for NodeCounter {
}
fn visit_foreign_item(&mut self, i: &ForeignItem) {
self.count += 1;
walk_item(self, i)
walk_item(self, i, ())
}
fn visit_item(&mut self, i: &Item) {
self.count += 1;
walk_item(self, i)
walk_item(self, i, ())
}
fn visit_local(&mut self, l: &Local) {
self.count += 1;
Expand Down Expand Up @@ -69,7 +69,7 @@ impl<'ast> Visitor<'ast> for NodeCounter {
}
fn visit_assoc_item(&mut self, ti: &AssocItem, ctxt: AssocCtxt) {
self.count += 1;
walk_assoc_item(self, ti, ctxt);
walk_item(self, ti, ctxt);
}
fn visit_trait_ref(&mut self, t: &TraitRef) {
self.count += 1;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
let Some(attr) = found_attr else {
self.check_not_pub_in_root(&item.vis, self.source_map.guess_head_span(item.span));
let prev_in_root = mem::replace(&mut self.in_root, false);
visit::walk_item(self, item);
visit::walk_item(self, item, ());
self.in_root = prev_in_root;
return;
};
Expand Down Expand Up @@ -248,7 +248,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
};

let prev_in_root = mem::replace(&mut self.in_root, false);
visit::walk_item(self, item);
visit::walk_item(self, item, ());
self.in_root = prev_in_root;
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
self.add_test_cases(item.id, span, prev_tests);
} else {
// But in those cases, we emit a lint to warn the user of these missing tests.
walk_item(&mut InnerItemLinter { sess: self.cx.ext_cx.sess }, &item);
walk_item(&mut InnerItemLinter { sess: self.cx.ext_cx.sess }, &item, ());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
_ => {}
}

visit::walk_item(self, item);
visit::walk_item(self, item, ());
}
}

Expand Down
21 changes: 11 additions & 10 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
fn visit_item(&mut self, it: &'a ast::Item) {
self.with_lint_attrs(it.id, &it.attrs, |cx| {
lint_callback!(cx, check_item, it);
ast_visit::walk_item(cx, it);
ast_visit::walk_item(cx, it, ());
lint_callback!(cx, check_item_post, it);
})
}

fn visit_foreign_item(&mut self, it: &'a ast::ForeignItem) {
self.with_lint_attrs(it.id, &it.attrs, |cx| {
ast_visit::walk_item(cx, it);
ast_visit::walk_item(cx, it, ());
})
}

Expand Down Expand Up @@ -230,15 +230,16 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
}

fn visit_assoc_item(&mut self, item: &'a ast::AssocItem, ctxt: ast_visit::AssocCtxt) {
self.with_lint_attrs(item.id, &item.attrs, |cx| match ctxt {
ast_visit::AssocCtxt::Trait => {
lint_callback!(cx, check_trait_item, item);
ast_visit::walk_assoc_item(cx, item, ctxt);
}
ast_visit::AssocCtxt::Impl => {
lint_callback!(cx, check_impl_item, item);
ast_visit::walk_assoc_item(cx, item, ctxt);
self.with_lint_attrs(item.id, &item.attrs, |cx| {
match ctxt {
ast_visit::AssocCtxt::Trait => {
lint_callback!(cx, check_trait_item, item);
}
ast_visit::AssocCtxt::Impl => {
lint_callback!(cx, check_impl_item, item);
}
}
ast_visit::walk_item(cx, item, ctxt);
});
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ fn global_allocator_spans(krate: &ast::Crate) -> Vec<Span> {
{
self.spans.push(item.span);
}
visit::walk_item(self, item)
visit::walk_item(self, item, ())
}
}

Expand All @@ -1127,7 +1127,7 @@ fn alloc_error_handler_spans(krate: &ast::Crate) -> Vec<Span> {
{
self.spans.push(item.span);
}
visit::walk_item(self, item)
visit::walk_item(self, item, ())
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2438,7 +2438,7 @@ fn get_spans_of_pat_idents(src: &str) -> Vec<Span> {
}
}
let mut v = PatIdentVisitor { spans: Vec::new() };
visit::walk_item(&mut v, &item);
visit::walk_item(&mut v, &item, ());
return v.spans;
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_passes/src/hir_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
record_variants!((self, i, i.kind, None, ast, ForeignItem, ForeignItemKind), [
Static, Fn, TyAlias, MacCall
]);
ast_visit::walk_item(self, i)
ast_visit::walk_item(self, i, ())
}

fn visit_item(&mut self, i: &'v ast::Item) {
Expand All @@ -502,7 +502,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
Delegation,
DelegationMac
]);
ast_visit::walk_item(self, i)
ast_visit::walk_item(self, i, ())
}

fn visit_local(&mut self, l: &'v ast::Local) {
Expand Down Expand Up @@ -626,7 +626,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
Delegation,
DelegationMac
]);
ast_visit::walk_assoc_item(self, i, ctxt);
ast_visit::walk_item(self, i, ctxt);
}

fn visit_param_bound(&mut self, b: &'v ast::GenericBound, _ctxt: BoundKind) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_passes/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
);

let parent_item = self.parent_item.replace(i);
visit::walk_item(self, i);
visit::walk_item(self, i, ());
self.parent_item = parent_item;
}

Expand Down Expand Up @@ -355,7 +355,7 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
generics,
);

visit::walk_assoc_item(self, i, ctxt);
visit::walk_item(self, i, ctxt);
}
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
self.parent_scope.macro_rules = match item.kind {
ItemKind::MacroDef(..) => {
let macro_rules_scope = self.define_macro(item);
visit::walk_item(self, item);
visit::walk_item(self, item, ());
macro_rules_scope
}
ItemKind::MacCall(..) => self.visit_invoc_in_module(item.id),
Expand All @@ -1327,7 +1327,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
item.kind.walk(item.span, item.id, &item.ident, &item.vis, (), self);
visit::walk_list!(self, visit_attribute, &item.attrs);
}
_ => visit::walk_item(self, item),
_ => visit::walk_item(self, item, ()),
}
match item.kind {
ItemKind::Mod(..) if self.contains_macro_use(&item.attrs) => {
Expand Down Expand Up @@ -1355,7 +1355,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
}

self.build_reduced_graph_for_foreign_item(foreign_item);
visit::walk_item(self, foreign_item);
visit::walk_item(self, foreign_item, ());
}

fn visit_block(&mut self, block: &'a Block) {
Expand Down Expand Up @@ -1420,7 +1420,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
self.r.impl_binding_keys.entry(impl_def_id).or_default().insert(key);
}

visit::walk_assoc_item(self, item, ctxt);
visit::walk_item(self, item, ctxt);
}

fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
}

self.item_span = item.span_with_attributes();
visit::walk_item(self, item);
visit::walk_item(self, item, ());
}

fn visit_use_tree(&mut self, use_tree: &'a ast::UseTree, id: ast::NodeId, nested: bool) {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
DefKind::Macro(macro_kind)
}
ItemKind::GlobalAsm(..) => DefKind::GlobalAsm,
ItemKind::Use(..) => return visit::walk_item(self, i),
ItemKind::Use(..) => return visit::walk_item(self, i, ()),
ItemKind::MacCall(..) | ItemKind::DelegationMac(..) => {
return self.visit_macro_invoc(i.id);
}
Expand All @@ -226,7 +226,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
}
_ => {}
}
visit::walk_item(this, i);
visit::walk_item(this, i, ());
})
});
}
Expand Down Expand Up @@ -301,7 +301,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {

let def = self.create_def(fi.id, fi.ident.name, def_kind, fi.span);

self.with_parent(def, |this| visit::walk_item(this, fi));
self.with_parent(def, |this| visit::walk_item(this, fi, ()));
}

fn visit_variant(&mut self, v: &'a Variant) {
Expand Down Expand Up @@ -365,7 +365,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
};

let def = self.create_def(i.id, i.ident.name, def_kind, i.span);
self.with_parent(def, |this| visit::walk_assoc_item(this, i, ctxt));
self.with_parent(def, |this| visit::walk_item(this, i, ctxt));
}

fn visit_pat(&mut self, pat: &'a Pat) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3055,7 +3055,7 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder {
return;
}
} else {
visit::walk_item(self, item);
visit::walk_item(self, item, ());
}
}
}
Expand Down
Loading

0 comments on commit dfd9184

Please sign in to comment.