Skip to content

Commit 7f58c24

Browse files
committed
Pass parts instead of entire item to WalkItemKind
1 parent fed840b commit 7f58c24

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

compiler/rustc_ast/src/visitors.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,10 @@ pub mod visit {
11631163
pub trait WalkItemKind: Sized {
11641164
fn walk<'a, V: Visitor<'a>>(
11651165
&'a self,
1166-
item: &'a Item<Self>,
1166+
id: NodeId,
1167+
span: Span,
1168+
vis: &'a Visibility,
1169+
ident: &'a Ident,
11671170
visitor: &mut V,
11681171
) -> V::Result;
11691172
}
@@ -1173,13 +1176,15 @@ pub mod visit {
11731176
impl WalkItemKind for ItemKind {
11741177
fn walk<'a, V: Visitor<'a>>(
11751178
&'a self,
1176-
item: &'a Item<Self>,
1179+
id: NodeId,
1180+
span: Span,
1181+
vis: &'a Visibility,
1182+
ident: &'a Ident,
11771183
visitor: &mut V,
11781184
) -> V::Result {
1179-
let Item { id, span, vis, ident, .. } = item;
11801185
match self {
11811186
ItemKind::ExternCrate(_rename) => {}
1182-
ItemKind::Use(use_tree) => try_visit!(visitor.visit_use_tree(use_tree, *id, false)),
1187+
ItemKind::Use(use_tree) => try_visit!(visitor.visit_use_tree(use_tree, id, false)),
11831188
ItemKind::Static(box StaticItem { ty, safety: _, mutability: _, expr }) => {
11841189
try_visit!(visitor.visit_ty(ty));
11851190
visit_opt!(visitor, visit_expr, expr);
@@ -1192,7 +1197,7 @@ pub mod visit {
11921197
ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
11931198
let kind =
11941199
FnKind::Fn(FnCtxt::Free, *ident, sig, vis, generics, body.as_deref());
1195-
try_visit!(visitor.visit_fn(kind, *span, *id));
1200+
try_visit!(visitor.visit_fn(kind, span, id));
11961201
}
11971202
ItemKind::Mod(_unsafety, mod_kind) => match mod_kind {
11981203
ModKind::Loaded(items, _inline, _inner_span) => {
@@ -1249,7 +1254,7 @@ pub mod visit {
12491254
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
12501255
}
12511256
ItemKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
1252-
ItemKind::MacroDef(ts) => try_visit!(visitor.visit_mac_def(ts, *id)),
1257+
ItemKind::MacroDef(ts) => try_visit!(visitor.visit_mac_def(ts, id)),
12531258
ItemKind::Delegation(box Delegation {
12541259
id,
12551260
qself,
@@ -1265,7 +1270,7 @@ pub mod visit {
12651270
}
12661271
ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
12671272
try_visit!(visitor.visit_qself(qself));
1268-
try_visit!(visitor.visit_path(prefix, *id));
1273+
try_visit!(visitor.visit_path(prefix, id));
12691274
if let Some(suffixes) = suffixes {
12701275
for (ident, rename) in suffixes {
12711276
visitor.visit_ident(*ident);
@@ -1285,11 +1290,11 @@ pub mod visit {
12851290
visitor: &mut V,
12861291
item: &'a Item<impl WalkItemKind>,
12871292
) -> V::Result {
1288-
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
1293+
let Item { id, span, ident, vis, attrs, kind, tokens: _ } = item;
12891294
walk_list!(visitor, visit_attribute, attrs);
12901295
try_visit!(visitor.visit_vis(vis));
1291-
try_visit!(visitor.visit_ident(ident));
1292-
try_visit!(kind.walk(item, visitor));
1296+
try_visit!(visitor.visit_ident(*ident));
1297+
try_visit!(kind.walk(*id, *span, vis, ident, visitor));
12931298
V::Result::output()
12941299
}
12951300

@@ -1363,18 +1368,20 @@ pub mod visit {
13631368
impl WalkItemKind for ForeignItemKind {
13641369
fn walk<'a, V: Visitor<'a>>(
13651370
&'a self,
1366-
item: &'a Item<Self>,
1371+
id: NodeId,
1372+
span: Span,
1373+
vis: &'a Visibility,
1374+
ident: &'a Ident,
13671375
visitor: &mut V,
13681376
) -> V::Result {
1369-
let &Item { id, span, ident, ref vis, .. } = item;
13701377
match self {
13711378
ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
13721379
try_visit!(visitor.visit_ty(ty));
13731380
visit_opt!(visitor, visit_expr, expr);
13741381
}
13751382
ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
13761383
let kind =
1377-
FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref());
1384+
FnKind::Fn(FnCtxt::Foreign, *ident, sig, vis, generics, body.as_deref());
13781385
try_visit!(visitor.visit_fn(kind, span, id));
13791386
}
13801387
ForeignItemKind::TyAlias(box TyAlias {

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
item.kind.walk(item.id, item.span, &item.vis, &item.ident, self);
13331333
visit::walk_list!(self, visit_attribute, &item.attrs);
13341334
}
13351335
_ => visit::walk_item(self, item),

0 commit comments

Comments
 (0)