Skip to content

Commit 952537d

Browse files
committed
Move Item visiting responsibility to WalkItemKind
1 parent fed840b commit 952537d

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

compiler/rustc_ast/src/visitors.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,6 @@ pub mod visit {
11621162

11631163
pub trait WalkItemKind: Sized {
11641164
fn walk<'a, V: Visitor<'a>>(
1165-
&'a self,
11661165
item: &'a Item<Self>,
11671166
visitor: &mut V,
11681167
) -> V::Result;
@@ -1172,12 +1171,14 @@ pub mod visit {
11721171

11731172
impl WalkItemKind for ItemKind {
11741173
fn walk<'a, V: Visitor<'a>>(
1175-
&'a self,
11761174
item: &'a Item<Self>,
11771175
visitor: &mut V,
11781176
) -> V::Result {
1179-
let Item { id, span, vis, ident, .. } = item;
1180-
match self {
1177+
let Item { id, span, ident, vis, attrs, kind, tokens: _ } = item;
1178+
walk_list!(visitor, visit_attribute, attrs);
1179+
try_visit!(visitor.visit_vis(vis));
1180+
try_visit!(visitor.visit_ident(*ident));
1181+
match kind {
11811182
ItemKind::ExternCrate(_rename) => {}
11821183
ItemKind::Use(use_tree) => try_visit!(visitor.visit_use_tree(use_tree, *id, false)),
11831184
ItemKind::Static(box StaticItem { ty, safety: _, mutability: _, expr }) => {
@@ -1281,15 +1282,11 @@ pub mod visit {
12811282
}
12821283
}
12831284

1284-
pub fn walk_item<'a, V: Visitor<'a>>(
1285+
pub fn walk_item<'a, V: Visitor<'a>, I: WalkItemKind>(
12851286
visitor: &mut V,
1286-
item: &'a Item<impl WalkItemKind>,
1287+
item: &'a Item<I>,
12871288
) -> V::Result {
1288-
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
1289-
walk_list!(visitor, visit_attribute, attrs);
1290-
try_visit!(visitor.visit_vis(vis));
1291-
try_visit!(visitor.visit_ident(ident));
1292-
try_visit!(kind.walk(item, visitor));
1289+
try_visit!(I::walk(item, visitor));
12931290
V::Result::output()
12941291
}
12951292

@@ -1362,20 +1359,22 @@ pub mod visit {
13621359

13631360
impl WalkItemKind for ForeignItemKind {
13641361
fn walk<'a, V: Visitor<'a>>(
1365-
&'a self,
13661362
item: &'a Item<Self>,
13671363
visitor: &mut V,
13681364
) -> V::Result {
1369-
let &Item { id, span, ident, ref vis, .. } = item;
1370-
match self {
1365+
let Item { id, span, ident, vis, attrs, kind, tokens: _ } = item;
1366+
walk_list!(visitor, visit_attribute, attrs);
1367+
try_visit!(visitor.visit_vis(vis));
1368+
try_visit!(visitor.visit_ident(*ident));
1369+
match kind {
13711370
ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
13721371
try_visit!(visitor.visit_ty(ty));
13731372
visit_opt!(visitor, visit_expr, expr);
13741373
}
13751374
ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
13761375
let kind =
1377-
FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref());
1378-
try_visit!(visitor.visit_fn(kind, span, id));
1376+
FnKind::Fn(FnCtxt::Foreign, *ident, sig, vis, generics, body.as_deref());
1377+
try_visit!(visitor.visit_fn(kind, *span, *id));
13791378
}
13801379
ForeignItemKind::TyAlias(box TyAlias {
13811380
generics,

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
use std::cell::Cell;
99

10-
use rustc_ast::visit::{self, AssocCtxt, Visitor, WalkItemKind};
10+
use rustc_ast::visit::{self, AssocCtxt, Visitor};
1111
use rustc_ast::{
1212
self as ast, AssocItem, AssocItemKind, Block, ForeignItem, ForeignItemKind, Impl, Item,
1313
ItemKind, MetaItemKind, NodeId, StmtKind,
@@ -1329,7 +1329,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
13291329
// This way they can use `macro_rules` defined later.
13301330
self.visit_vis(&item.vis);
13311331
self.visit_ident(item.ident);
1332-
item.kind.walk(item, self);
1332+
visit::walk_item(self, item);
13331333
visit::walk_list!(self, visit_attribute, &item.attrs);
13341334
}
13351335
_ => visit::walk_item(self, item),

0 commit comments

Comments
 (0)