Skip to content

Commit 5dd53f3

Browse files
committed
Unimpl mut WalkItemKind for AssocItemKind
1 parent 7299c60 commit 5dd53f3

File tree

4 files changed

+88
-80
lines changed

4 files changed

+88
-80
lines changed

compiler/rustc_ast/src/visitors.rs

Lines changed: 83 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ macro_rules! mutability_dependent {
7777
fn flat_map_assoc_item(
7878
&mut self,
7979
i: P<AssocItem>,
80-
_ctxt: AssocCtxt,
80+
ctxt: AssocCtxt,
8181
) -> SmallVec<[P<AssocItem>; 1]> {
82-
walk_flat_map_item(self, i)
82+
walk_flat_map_assoc_item(self, i, ctxt)
8383
}
8484

8585
fn visit_coroutine_kind(&mut self, a: &mut CoroutineKind) {
@@ -2424,79 +2424,6 @@ pub mod mut_visit {
24242424
}
24252425
}
24262426

2427-
impl WalkItemKind for AssocItemKind {
2428-
fn walk(
2429-
&mut self,
2430-
id: NodeId,
2431-
span: Span,
2432-
_vis: &mut Visibility,
2433-
_ident: &mut Ident,
2434-
visitor: &mut impl MutVisitor
2435-
) {
2436-
match self {
2437-
AssocItemKind::Const(item) => {
2438-
visit_const_item(item, visitor);
2439-
}
2440-
AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
2441-
visit_defaultness(visitor, defaultness);
2442-
visitor.visit_fn(FnKind::Fn(sig, generics, body), span, id);
2443-
}
2444-
AssocItemKind::Type(box TyAlias {
2445-
defaultness,
2446-
generics,
2447-
where_clauses,
2448-
bounds,
2449-
ty,
2450-
}) => {
2451-
visit_defaultness(visitor, defaultness);
2452-
visitor.visit_generics(generics);
2453-
visit_bounds(visitor, bounds, BoundKind::Bound);
2454-
visit_opt(ty, |ty| visitor.visit_ty(ty));
2455-
walk_ty_alias_where_clauses(visitor, where_clauses);
2456-
}
2457-
AssocItemKind::MacCall(mac) => visitor.visit_mac_call(mac),
2458-
AssocItemKind::Delegation(box Delegation {
2459-
id,
2460-
qself,
2461-
path,
2462-
rename,
2463-
body,
2464-
from_glob: _,
2465-
}) => {
2466-
visitor.visit_id(id);
2467-
visitor.visit_qself(qself);
2468-
visitor.visit_path(path, *id);
2469-
if let Some(rename) = rename {
2470-
visitor.visit_ident(rename);
2471-
}
2472-
if let Some(body) = body {
2473-
visitor.visit_block(body);
2474-
}
2475-
}
2476-
AssocItemKind::DelegationMac(box DelegationMac {
2477-
qself,
2478-
prefix,
2479-
suffixes,
2480-
body,
2481-
}) => {
2482-
visitor.visit_qself(qself);
2483-
visitor.visit_path(prefix, id);
2484-
if let Some(suffixes) = suffixes {
2485-
for (ident, rename) in suffixes {
2486-
visitor.visit_ident(ident);
2487-
if let Some(rename) = rename {
2488-
visitor.visit_ident(rename);
2489-
}
2490-
}
2491-
}
2492-
if let Some(body) = body {
2493-
visitor.visit_block(body);
2494-
}
2495-
}
2496-
}
2497-
}
2498-
}
2499-
25002427
fn visit_const_item<T: MutVisitor>(
25012428
ConstItem { defaultness, generics, ty, expr }: &mut ConstItem,
25022429
visitor: &mut T,
@@ -2530,6 +2457,87 @@ pub mod mut_visit {
25302457
smallvec![item]
25312458
}
25322459

2460+
pub fn walk_assoc_item(visitor: &mut impl MutVisitor, item: &mut Item<AssocItemKind>, _ctxt: AssocCtxt) {
2461+
let Item { attrs, id, span, vis, ident, kind, tokens } = item;
2462+
visitor.visit_id(id);
2463+
visit_attrs(visitor, attrs);
2464+
visitor.visit_vis(vis);
2465+
visitor.visit_ident(ident);
2466+
match kind {
2467+
AssocItemKind::Const(item) => {
2468+
visit_const_item(item, visitor);
2469+
}
2470+
AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
2471+
visit_defaultness(visitor, defaultness);
2472+
visitor.visit_fn(FnKind::Fn(sig, generics, body), *span, *id);
2473+
}
2474+
AssocItemKind::Type(box TyAlias {
2475+
defaultness,
2476+
generics,
2477+
where_clauses,
2478+
bounds,
2479+
ty,
2480+
}) => {
2481+
visit_defaultness(visitor, defaultness);
2482+
visitor.visit_generics(generics);
2483+
visit_bounds(visitor, bounds, BoundKind::Bound);
2484+
visit_opt(ty, |ty| visitor.visit_ty(ty));
2485+
walk_ty_alias_where_clauses(visitor, where_clauses);
2486+
}
2487+
AssocItemKind::MacCall(mac) => visitor.visit_mac_call(mac),
2488+
AssocItemKind::Delegation(box Delegation {
2489+
id,
2490+
qself,
2491+
path,
2492+
rename,
2493+
body,
2494+
from_glob: _,
2495+
}) => {
2496+
visitor.visit_id(id);
2497+
visitor.visit_qself(qself);
2498+
visitor.visit_path(path, *id);
2499+
if let Some(rename) = rename {
2500+
visitor.visit_ident(rename);
2501+
}
2502+
if let Some(body) = body {
2503+
visitor.visit_block(body);
2504+
}
2505+
}
2506+
AssocItemKind::DelegationMac(box DelegationMac {
2507+
qself,
2508+
prefix,
2509+
suffixes,
2510+
body,
2511+
}) => {
2512+
visitor.visit_qself(qself);
2513+
visitor.visit_path(prefix, *id);
2514+
if let Some(suffixes) = suffixes {
2515+
for (ident, rename) in suffixes {
2516+
visitor.visit_ident(ident);
2517+
if let Some(rename) = rename {
2518+
visitor.visit_ident(rename);
2519+
}
2520+
}
2521+
}
2522+
if let Some(body) = body {
2523+
visitor.visit_block(body);
2524+
}
2525+
}
2526+
}
2527+
visit_lazy_tts(visitor, tokens);
2528+
visitor.visit_span(span);
2529+
}
2530+
2531+
pub fn walk_flat_map_assoc_item(
2532+
visitor: &mut impl MutVisitor,
2533+
mut item: P<Item<AssocItemKind>>,
2534+
ctxt: AssocCtxt
2535+
) -> SmallVec<[P<Item<AssocItemKind>>; 1]> {
2536+
walk_assoc_item(visitor, item.deref_mut(), ctxt);
2537+
smallvec![item]
2538+
}
2539+
2540+
25332541
impl WalkItemKind for ForeignItemKind {
25342542
fn walk(
25352543
&mut self,

compiler/rustc_builtin_macros/src/cfg_eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ impl MutVisitor for CfgEval<'_> {
247247
fn flat_map_assoc_item(
248248
&mut self,
249249
item: P<ast::AssocItem>,
250-
_ctxt: AssocCtxt,
250+
ctxt: AssocCtxt,
251251
) -> SmallVec<[P<ast::AssocItem>; 1]> {
252252
let item = configure!(self, item);
253-
mut_visit::walk_flat_map_item(self, item)
253+
mut_visit::walk_flat_map_assoc_item(self, item, ctxt)
254254
}
255255

256256
fn flat_map_foreign_item(

compiler/rustc_expand/src/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag>
12941294
fragment.make_trait_items()
12951295
}
12961296
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1297-
walk_flat_map_item(visitor, self.wrapped)
1297+
walk_flat_map_assoc_item(visitor, self.wrapped, AssocCtxt::Trait)
12981298
}
12991299
fn is_mac_call(&self) -> bool {
13001300
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
@@ -1335,7 +1335,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag>
13351335
fragment.make_impl_items()
13361336
}
13371337
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1338-
walk_flat_map_item(visitor, self.wrapped)
1338+
walk_flat_map_assoc_item(visitor, self.wrapped, AssocCtxt::Impl)
13391339
}
13401340
fn is_mac_call(&self) -> bool {
13411341
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))

compiler/rustc_expand/src/placeholders.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl MutVisitor for PlaceholderExpander {
286286
AssocCtxt::Impl => it.make_impl_items(),
287287
}
288288
}
289-
_ => walk_flat_map_item(self, item),
289+
_ => walk_flat_map_assoc_item(self, item, ctxt),
290290
}
291291
}
292292

0 commit comments

Comments
 (0)