Skip to content

Commit

Permalink
Add back wrappers for walk_item
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcabrajac committed Nov 20, 2024
1 parent a767c7a commit 94b756b
Show file tree
Hide file tree
Showing 21 changed files with 87 additions and 65 deletions.
16 changes: 12 additions & 4 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ pub trait MutVisitor: Sized {
}

fn visit_foreign_item(&mut self, ni: &mut P<ForeignItem>) {
walk_item(self, ni, ());
walk_item(self, ni);
}

fn flat_map_foreign_item(&mut self, ni: P<ForeignItem>) -> SmallVec<[P<ForeignItem>; 1]> {
walk_flat_map_foreign_item(self, ni)
}

fn visit_item(&mut self, i: &mut P<Item>) {
walk_item(self, i, ());
walk_item(self, i);
}

fn flat_map_item(&mut self, i: P<Item>) -> SmallVec<[P<Item>; 1]> {
Expand All @@ -133,7 +133,7 @@ pub trait MutVisitor: Sized {
}

fn visit_assoc_item(&mut self, i: &mut P<AssocItem>, ctxt: AssocCtxt) {
walk_item(self, i, ctxt)
walk_assoc_item(self, i, ctxt)
}

fn flat_map_assoc_item(
Expand Down Expand Up @@ -1395,7 +1395,15 @@ pub fn walk_crate<T: MutVisitor>(vis: &mut T, krate: &mut Crate) {
vis.visit_span(inject_use_span);
}

pub fn walk_item<K: WalkItemKind>(
pub fn walk_item(visitor: &mut impl MutVisitor, item: &mut P<Item<impl WalkItemKind<Ctxt = ()>>>) {
walk_item_ctxt(visitor, item, ())
}

pub fn walk_assoc_item(visitor: &mut impl MutVisitor, item: &mut P<AssocItem>, ctxt: AssocCtxt) {
walk_item_ctxt(visitor, item, ctxt)
}

fn walk_item_ctxt<K: WalkItemKind>(
visitor: &mut impl MutVisitor,
item: &mut P<Item<K>>,
ctxt: K::Ctxt,
Expand Down
23 changes: 19 additions & 4 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_item(self, i, ctxt)
walk_assoc_item(self, i, ctxt)
}
fn visit_trait_ref(&mut self, t: &'ast TraitRef) -> Self::Result {
walk_trait_ref(self, t)
Expand Down Expand Up @@ -918,7 +918,22 @@ impl WalkItemKind for AssocItemKind {
}
}

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

pub fn walk_assoc_item<'a, V: Visitor<'a>>(
visitor: &mut V,
item: &'a AssocItem,
ctxt: AssocCtxt,
) -> V::Result {
walk_item_ctxt(visitor, item, ctxt)
}

fn walk_item_ctxt<'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_item(self, item, ctxt);
visit::walk_assoc_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_item(this, item, ctxt))
this.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)),
_ => self.with_in_trait_impl(None, |this| visit::walk_assoc_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_item(self, i, ctxt)
visit::walk_assoc_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_item(self, ti, ctxt);
walk_assoc_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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -200,7 +200,7 @@ struct EntryPointCleaner<'a> {
impl<'a> MutVisitor for EntryPointCleaner<'a> {
fn visit_item(&mut self, item: &mut P<ast::Item>) {
self.depth += 1;
ast::mut_visit::walk_item(self, item, ());
ast::mut_visit::walk_item(self, item);
self.depth -= 1;

// Remove any #[rustc_main] or #[start] from the AST so it doesn't
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
6 changes: 3 additions & 3 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 @@ -239,7 +239,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
lint_callback!(cx, check_impl_item, item);
}
}
ast_visit::walk_item(cx, item, ctxt);
ast_visit::walk_assoc_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_item(self, i, ctxt);
ast_visit::walk_assoc_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_item(self, i, ctxt);
visit::walk_assoc_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_item(self, item, ctxt);
visit::walk_assoc_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
Loading

0 comments on commit 94b756b

Please sign in to comment.