Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8969b39

Browse files
authoredNov 21, 2024··
Unrolled build for rust-lang#133153
Rollup merge of rust-lang#133153 - maxcabrajac:flat_maps, r=petrochenkov Add visits to nodes that already have flat_maps in ast::MutVisitor This PR aims to add `visit_` methods for every node that has a `flat_map_` in MutVisitor, giving implementers free choice over overriding `flat_map` for 1-to-n conversions or `visit` for a 1-to-1. There is one major problem: `flat_map_stmt`. While all other default implementations of `flat_map`s are 1-to-1 conversion, as they either only call visits or a internal 1-to-many conversions are natural, `flat_map_stmt` doesn't follow this pattern. `flat_map_stmt`'s default implementation is a 1-to-n conversion that panics if n > 1 (effectively being a 1-to-[0;1]). This means that it cannot be used as is for a default `visit_stmt`, which would be required to be a 1-to-1. Implementing `visit_stmt` without runtime checks would require it to reach over a potential `flat_map_item` or `filter_map_expr` overrides and call for their `visit` counterparts directly. Other than that, if we want to keep the behavior of `flat_map_stmt` it cannot call `visit_stmt` internally. To me, it seems reasonable to make all default implementations 1-to-1 conversions and let implementers handle `visit_stmt` if they need it, but I don't know if calling `visit` directly when a 1-to-1 is required is ok or not. related to rust-lang#128974 & rust-lang#127615 r? ``@petrochenkov``
2 parents 318f96a + 01b26e6 commit 8969b39

File tree

7 files changed

+177
-88
lines changed

7 files changed

+177
-88
lines changed
 

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 128 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,16 @@ pub trait MutVisitor: Sized {
104104
walk_use_tree(self, use_tree);
105105
}
106106

107+
fn visit_foreign_item(&mut self, ni: &mut P<ForeignItem>) {
108+
walk_item(self, ni);
109+
}
110+
107111
fn flat_map_foreign_item(&mut self, ni: P<ForeignItem>) -> SmallVec<[P<ForeignItem>; 1]> {
108-
walk_flat_map_item(self, ni)
112+
walk_flat_map_foreign_item(self, ni)
113+
}
114+
115+
fn visit_item(&mut self, i: &mut P<Item>) {
116+
walk_item(self, i);
109117
}
110118

111119
fn flat_map_item(&mut self, i: P<Item>) -> SmallVec<[P<Item>; 1]> {
@@ -116,10 +124,18 @@ pub trait MutVisitor: Sized {
116124
walk_fn_header(self, header);
117125
}
118126

127+
fn visit_field_def(&mut self, fd: &mut FieldDef) {
128+
walk_field_def(self, fd);
129+
}
130+
119131
fn flat_map_field_def(&mut self, fd: FieldDef) -> SmallVec<[FieldDef; 1]> {
120132
walk_flat_map_field_def(self, fd)
121133
}
122134

135+
fn visit_assoc_item(&mut self, i: &mut P<AssocItem>, ctxt: AssocCtxt) {
136+
walk_assoc_item(self, i, ctxt)
137+
}
138+
123139
fn flat_map_assoc_item(
124140
&mut self,
125141
i: P<AssocItem>,
@@ -153,6 +169,10 @@ pub trait MutVisitor: Sized {
153169
walk_flat_map_stmt(self, s)
154170
}
155171

172+
fn visit_arm(&mut self, arm: &mut Arm) {
173+
walk_arm(self, arm);
174+
}
175+
156176
fn flat_map_arm(&mut self, arm: Arm) -> SmallVec<[Arm; 1]> {
157177
walk_flat_map_arm(self, arm)
158178
}
@@ -199,6 +219,10 @@ pub trait MutVisitor: Sized {
199219
walk_foreign_mod(self, nm);
200220
}
201221

222+
fn visit_variant(&mut self, v: &mut Variant) {
223+
walk_variant(self, v);
224+
}
225+
202226
fn flat_map_variant(&mut self, v: Variant) -> SmallVec<[Variant; 1]> {
203227
walk_flat_map_variant(self, v)
204228
}
@@ -251,6 +275,10 @@ pub trait MutVisitor: Sized {
251275
walk_attribute(self, at);
252276
}
253277

278+
fn visit_param(&mut self, param: &mut Param) {
279+
walk_param(self, param);
280+
}
281+
254282
fn flat_map_param(&mut self, param: Param) -> SmallVec<[Param; 1]> {
255283
walk_flat_map_param(self, param)
256284
}
@@ -271,6 +299,10 @@ pub trait MutVisitor: Sized {
271299
walk_variant_data(self, vdata);
272300
}
273301

302+
fn visit_generic_param(&mut self, param: &mut GenericParam) {
303+
walk_generic_param(self, param)
304+
}
305+
274306
fn flat_map_generic_param(&mut self, param: GenericParam) -> SmallVec<[GenericParam; 1]> {
275307
walk_flat_map_generic_param(self, param)
276308
}
@@ -287,6 +319,10 @@ pub trait MutVisitor: Sized {
287319
walk_mt(self, mt);
288320
}
289321

322+
fn visit_expr_field(&mut self, f: &mut ExprField) {
323+
walk_expr_field(self, f);
324+
}
325+
290326
fn flat_map_expr_field(&mut self, f: ExprField) -> SmallVec<[ExprField; 1]> {
291327
walk_flat_map_expr_field(self, f)
292328
}
@@ -311,6 +347,10 @@ pub trait MutVisitor: Sized {
311347
// Do nothing.
312348
}
313349

350+
fn visit_pat_field(&mut self, fp: &mut PatField) {
351+
walk_pat_field(self, fp)
352+
}
353+
314354
fn flat_map_pat_field(&mut self, fp: PatField) -> SmallVec<[PatField; 1]> {
315355
walk_flat_map_pat_field(self, fp)
316356
}
@@ -429,16 +469,20 @@ pub fn visit_delim_span<T: MutVisitor>(vis: &mut T, DelimSpan { open, close }: &
429469
vis.visit_span(close);
430470
}
431471

432-
pub fn walk_flat_map_pat_field<T: MutVisitor>(
433-
vis: &mut T,
434-
mut fp: PatField,
435-
) -> SmallVec<[PatField; 1]> {
436-
let PatField { attrs, id, ident, is_placeholder: _, is_shorthand: _, pat, span } = &mut fp;
472+
pub fn walk_pat_field<T: MutVisitor>(vis: &mut T, fp: &mut PatField) {
473+
let PatField { attrs, id, ident, is_placeholder: _, is_shorthand: _, pat, span } = fp;
437474
vis.visit_id(id);
438475
visit_attrs(vis, attrs);
439476
vis.visit_ident(ident);
440477
vis.visit_pat(pat);
441478
vis.visit_span(span);
479+
}
480+
481+
pub fn walk_flat_map_pat_field<T: MutVisitor>(
482+
vis: &mut T,
483+
mut fp: PatField,
484+
) -> SmallVec<[PatField; 1]> {
485+
vis.visit_pat_field(&mut fp);
442486
smallvec![fp]
443487
}
444488

@@ -459,14 +503,18 @@ fn walk_use_tree<T: MutVisitor>(vis: &mut T, use_tree: &mut UseTree) {
459503
vis.visit_span(span);
460504
}
461505

462-
pub fn walk_flat_map_arm<T: MutVisitor>(vis: &mut T, mut arm: Arm) -> SmallVec<[Arm; 1]> {
463-
let Arm { attrs, pat, guard, body, span, id, is_placeholder: _ } = &mut arm;
506+
pub fn walk_arm<T: MutVisitor>(vis: &mut T, arm: &mut Arm) {
507+
let Arm { attrs, pat, guard, body, span, id, is_placeholder: _ } = arm;
464508
vis.visit_id(id);
465509
visit_attrs(vis, attrs);
466510
vis.visit_pat(pat);
467511
visit_opt(guard, |guard| vis.visit_expr(guard));
468512
visit_opt(body, |body| vis.visit_expr(body));
469513
vis.visit_span(span);
514+
}
515+
516+
pub fn walk_flat_map_arm<T: MutVisitor>(vis: &mut T, mut arm: Arm) -> SmallVec<[Arm; 1]> {
517+
vis.visit_arm(&mut arm);
470518
smallvec![arm]
471519
}
472520

@@ -543,18 +591,22 @@ fn walk_foreign_mod<T: MutVisitor>(vis: &mut T, foreign_mod: &mut ForeignMod) {
543591
items.flat_map_in_place(|item| vis.flat_map_foreign_item(item));
544592
}
545593

546-
pub fn walk_flat_map_variant<T: MutVisitor>(
547-
visitor: &mut T,
548-
mut variant: Variant,
549-
) -> SmallVec<[Variant; 1]> {
550-
let Variant { ident, vis, attrs, id, data, disr_expr, span, is_placeholder: _ } = &mut variant;
594+
pub fn walk_variant<T: MutVisitor>(visitor: &mut T, variant: &mut Variant) {
595+
let Variant { ident, vis, attrs, id, data, disr_expr, span, is_placeholder: _ } = variant;
551596
visitor.visit_id(id);
552597
visit_attrs(visitor, attrs);
553598
visitor.visit_vis(vis);
554599
visitor.visit_ident(ident);
555600
visitor.visit_variant_data(data);
556601
visit_opt(disr_expr, |disr_expr| visitor.visit_anon_const(disr_expr));
557602
visitor.visit_span(span);
603+
}
604+
605+
pub fn walk_flat_map_variant<T: MutVisitor>(
606+
vis: &mut T,
607+
mut variant: Variant,
608+
) -> SmallVec<[Variant; 1]> {
609+
vis.visit_variant(&mut variant);
558610
smallvec![variant]
559611
}
560612

@@ -685,13 +737,17 @@ fn walk_meta_item<T: MutVisitor>(vis: &mut T, mi: &mut MetaItem) {
685737
vis.visit_span(span);
686738
}
687739

688-
pub fn walk_flat_map_param<T: MutVisitor>(vis: &mut T, mut param: Param) -> SmallVec<[Param; 1]> {
689-
let Param { attrs, id, pat, span, ty, is_placeholder: _ } = &mut param;
740+
pub fn walk_param<T: MutVisitor>(vis: &mut T, param: &mut Param) {
741+
let Param { attrs, id, pat, span, ty, is_placeholder: _ } = param;
690742
vis.visit_id(id);
691743
visit_attrs(vis, attrs);
692744
vis.visit_pat(pat);
693745
vis.visit_ty(ty);
694746
vis.visit_span(span);
747+
}
748+
749+
pub fn walk_flat_map_param<T: MutVisitor>(vis: &mut T, mut param: Param) -> SmallVec<[Param; 1]> {
750+
vis.visit_param(&mut param);
695751
smallvec![param]
696752
}
697753

@@ -950,11 +1006,8 @@ fn walk_precise_capturing_arg<T: MutVisitor>(vis: &mut T, arg: &mut PreciseCaptu
9501006
}
9511007
}
9521008

953-
pub fn walk_flat_map_generic_param<T: MutVisitor>(
954-
vis: &mut T,
955-
mut param: GenericParam,
956-
) -> SmallVec<[GenericParam; 1]> {
957-
let GenericParam { id, ident, attrs, bounds, kind, colon_span, is_placeholder: _ } = &mut param;
1009+
pub fn walk_generic_param<T: MutVisitor>(vis: &mut T, param: &mut GenericParam) {
1010+
let GenericParam { id, ident, attrs, bounds, kind, colon_span, is_placeholder: _ } = param;
9581011
vis.visit_id(id);
9591012
visit_attrs(vis, attrs);
9601013
vis.visit_ident(ident);
@@ -972,6 +1025,13 @@ pub fn walk_flat_map_generic_param<T: MutVisitor>(
9721025
if let Some(colon_span) = colon_span {
9731026
vis.visit_span(colon_span);
9741027
}
1028+
}
1029+
1030+
pub fn walk_flat_map_generic_param<T: MutVisitor>(
1031+
vis: &mut T,
1032+
mut param: GenericParam,
1033+
) -> SmallVec<[GenericParam; 1]> {
1034+
vis.visit_generic_param(&mut param);
9751035
smallvec![param]
9761036
}
9771037

@@ -1054,30 +1114,38 @@ fn walk_poly_trait_ref<T: MutVisitor>(vis: &mut T, p: &mut PolyTraitRef) {
10541114
vis.visit_span(span);
10551115
}
10561116

1057-
pub fn walk_flat_map_field_def<T: MutVisitor>(
1058-
visitor: &mut T,
1059-
mut fd: FieldDef,
1060-
) -> SmallVec<[FieldDef; 1]> {
1061-
let FieldDef { span, ident, vis, id, ty, attrs, is_placeholder: _ } = &mut fd;
1117+
pub fn walk_field_def<T: MutVisitor>(visitor: &mut T, fd: &mut FieldDef) {
1118+
let FieldDef { span, ident, vis, id, ty, attrs, is_placeholder: _ } = fd;
10621119
visitor.visit_id(id);
10631120
visit_attrs(visitor, attrs);
10641121
visitor.visit_vis(vis);
10651122
visit_opt(ident, |ident| visitor.visit_ident(ident));
10661123
visitor.visit_ty(ty);
10671124
visitor.visit_span(span);
1068-
smallvec![fd]
10691125
}
10701126

1071-
pub fn walk_flat_map_expr_field<T: MutVisitor>(
1127+
pub fn walk_flat_map_field_def<T: MutVisitor>(
10721128
vis: &mut T,
1073-
mut f: ExprField,
1074-
) -> SmallVec<[ExprField; 1]> {
1075-
let ExprField { ident, expr, span, is_shorthand: _, attrs, id, is_placeholder: _ } = &mut f;
1129+
mut fd: FieldDef,
1130+
) -> SmallVec<[FieldDef; 1]> {
1131+
vis.visit_field_def(&mut fd);
1132+
smallvec![fd]
1133+
}
1134+
1135+
pub fn walk_expr_field<T: MutVisitor>(vis: &mut T, f: &mut ExprField) {
1136+
let ExprField { ident, expr, span, is_shorthand: _, attrs, id, is_placeholder: _ } = f;
10761137
vis.visit_id(id);
10771138
visit_attrs(vis, attrs);
10781139
vis.visit_ident(ident);
10791140
vis.visit_expr(expr);
10801141
vis.visit_span(span);
1142+
}
1143+
1144+
pub fn walk_flat_map_expr_field<T: MutVisitor>(
1145+
vis: &mut T,
1146+
mut f: ExprField,
1147+
) -> SmallVec<[ExprField; 1]> {
1148+
vis.visit_expr_field(&mut f);
10811149
smallvec![f]
10821150
}
10831151

@@ -1331,18 +1399,19 @@ pub fn walk_crate<T: MutVisitor>(vis: &mut T, krate: &mut Crate) {
13311399
vis.visit_span(inject_use_span);
13321400
}
13331401

1334-
pub fn walk_flat_map_item<K: WalkItemKind<Ctxt = ()>>(
1335-
visitor: &mut impl MutVisitor,
1336-
item: P<Item<K>>,
1337-
) -> SmallVec<[P<Item<K>>; 1]> {
1338-
walk_flat_map_assoc_item(visitor, item, ())
1402+
pub fn walk_item(visitor: &mut impl MutVisitor, item: &mut P<Item<impl WalkItemKind<Ctxt = ()>>>) {
1403+
walk_item_ctxt(visitor, item, ())
1404+
}
1405+
1406+
pub fn walk_assoc_item(visitor: &mut impl MutVisitor, item: &mut P<AssocItem>, ctxt: AssocCtxt) {
1407+
walk_item_ctxt(visitor, item, ctxt)
13391408
}
13401409

1341-
pub fn walk_flat_map_assoc_item<K: WalkItemKind>(
1410+
fn walk_item_ctxt<K: WalkItemKind>(
13421411
visitor: &mut impl MutVisitor,
1343-
mut item: P<Item<K>>,
1412+
item: &mut P<Item<K>>,
13441413
ctxt: K::Ctxt,
1345-
) -> SmallVec<[P<Item<K>>; 1]> {
1414+
) {
13461415
let Item { ident, attrs, id, kind, vis, span, tokens } = item.deref_mut();
13471416
visitor.visit_id(id);
13481417
visit_attrs(visitor, attrs);
@@ -1351,6 +1420,27 @@ pub fn walk_flat_map_assoc_item<K: WalkItemKind>(
13511420
kind.walk(*span, *id, ident, vis, ctxt, visitor);
13521421
visit_lazy_tts(visitor, tokens);
13531422
visitor.visit_span(span);
1423+
}
1424+
1425+
pub fn walk_flat_map_item(vis: &mut impl MutVisitor, mut item: P<Item>) -> SmallVec<[P<Item>; 1]> {
1426+
vis.visit_item(&mut item);
1427+
smallvec![item]
1428+
}
1429+
1430+
pub fn walk_flat_map_foreign_item(
1431+
vis: &mut impl MutVisitor,
1432+
mut item: P<ForeignItem>,
1433+
) -> SmallVec<[P<ForeignItem>; 1]> {
1434+
vis.visit_foreign_item(&mut item);
1435+
smallvec![item]
1436+
}
1437+
1438+
pub fn walk_flat_map_assoc_item(
1439+
vis: &mut impl MutVisitor,
1440+
mut item: P<AssocItem>,
1441+
ctxt: AssocCtxt,
1442+
) -> SmallVec<[P<AssocItem>; 1]> {
1443+
vis.visit_assoc_item(&mut item, ctxt);
13541444
smallvec![item]
13551445
}
13561446

‎compiler/rustc_ast/src/visit.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,6 @@ impl WalkItemKind for ItemKind {
463463
}
464464
}
465465

466-
pub fn walk_item<'a, V: Visitor<'a>>(
467-
visitor: &mut V,
468-
item: &'a Item<impl WalkItemKind<Ctxt = ()>>,
469-
) -> V::Result {
470-
walk_assoc_item(visitor, item, ())
471-
}
472-
473466
pub fn walk_enum_def<'a, V: Visitor<'a>>(
474467
visitor: &mut V,
475468
EnumDef { variants }: &'a EnumDef,
@@ -931,7 +924,22 @@ impl WalkItemKind for AssocItemKind {
931924
}
932925
}
933926

934-
pub fn walk_assoc_item<'a, V: Visitor<'a>, K: WalkItemKind>(
927+
pub fn walk_item<'a, V: Visitor<'a>>(
928+
visitor: &mut V,
929+
item: &'a Item<impl WalkItemKind<Ctxt = ()>>,
930+
) -> V::Result {
931+
walk_item_ctxt(visitor, item, ())
932+
}
933+
934+
pub fn walk_assoc_item<'a, V: Visitor<'a>>(
935+
visitor: &mut V,
936+
item: &'a AssocItem,
937+
ctxt: AssocCtxt,
938+
) -> V::Result {
939+
walk_item_ctxt(visitor, item, ctxt)
940+
}
941+
942+
fn walk_item_ctxt<'a, V: Visitor<'a>, K: WalkItemKind>(
935943
visitor: &mut V,
936944
item: &'a Item<K>,
937945
ctxt: K::Ctxt,

‎compiler/rustc_builtin_macros/src/cfg_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl MutVisitor for CfgEval<'_> {
215215
foreign_item: P<ast::ForeignItem>,
216216
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
217217
let foreign_item = configure!(self, foreign_item);
218-
mut_visit::walk_flat_map_item(self, foreign_item)
218+
mut_visit::walk_flat_map_foreign_item(self, foreign_item)
219219
}
220220

221221
fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> {

‎compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Code that generates a test runner to run all the tests in a crate
22

3-
use std::{iter, mem};
3+
use std::mem;
44

55
use rustc_ast as ast;
66
use rustc_ast::entry::EntryPointType;
@@ -19,7 +19,7 @@ use rustc_span::hygiene::{AstPass, SyntaxContext, Transparency};
1919
use rustc_span::symbol::{Ident, Symbol, sym};
2020
use rustc_span::{DUMMY_SP, Span};
2121
use rustc_target::spec::PanicStrategy;
22-
use smallvec::{SmallVec, smallvec};
22+
use smallvec::smallvec;
2323
use thin_vec::{ThinVec, thin_vec};
2424
use tracing::debug;
2525

@@ -129,8 +129,9 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
129129
c.items.push(mk_main(&mut self.cx));
130130
}
131131

132-
fn flat_map_item(&mut self, mut i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
133-
let item = &mut *i;
132+
fn visit_item(&mut self, item: &mut P<ast::Item>) {
133+
let item = &mut **item;
134+
134135
if let Some(name) = get_test_name(&item) {
135136
debug!("this is a test item");
136137

@@ -158,7 +159,6 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
158159
// But in those cases, we emit a lint to warn the user of these missing tests.
159160
walk_item(&mut InnerItemLinter { sess: self.cx.ext_cx.sess }, &item);
160161
}
161-
smallvec![i]
162162
}
163163
}
164164

@@ -198,40 +198,30 @@ struct EntryPointCleaner<'a> {
198198
}
199199

200200
impl<'a> MutVisitor for EntryPointCleaner<'a> {
201-
fn flat_map_item(&mut self, i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
201+
fn visit_item(&mut self, item: &mut P<ast::Item>) {
202202
self.depth += 1;
203-
let item = walk_flat_map_item(self, i).expect_one("noop did something");
203+
ast::mut_visit::walk_item(self, item);
204204
self.depth -= 1;
205205

206206
// Remove any #[rustc_main] or #[start] from the AST so it doesn't
207207
// clash with the one we're going to add, but mark it as
208208
// #[allow(dead_code)] to avoid printing warnings.
209-
let item = match entry_point_type(&item, self.depth == 0) {
209+
match entry_point_type(&item, self.depth == 0) {
210210
EntryPointType::MainNamed | EntryPointType::RustcMainAttr | EntryPointType::Start => {
211-
item.map(|ast::Item { id, ident, attrs, kind, vis, span, tokens }| {
212-
let allow_dead_code = attr::mk_attr_nested_word(
213-
&self.sess.psess.attr_id_generator,
214-
ast::AttrStyle::Outer,
215-
ast::Safety::Default,
216-
sym::allow,
217-
sym::dead_code,
218-
self.def_site,
219-
);
220-
let attrs = attrs
221-
.into_iter()
222-
.filter(|attr| {
223-
!attr.has_name(sym::rustc_main) && !attr.has_name(sym::start)
224-
})
225-
.chain(iter::once(allow_dead_code))
226-
.collect();
227-
228-
ast::Item { id, ident, attrs, kind, vis, span, tokens }
229-
})
211+
let allow_dead_code = attr::mk_attr_nested_word(
212+
&self.sess.psess.attr_id_generator,
213+
ast::AttrStyle::Outer,
214+
ast::Safety::Default,
215+
sym::allow,
216+
sym::dead_code,
217+
self.def_site,
218+
);
219+
item.attrs
220+
.retain(|attr| !attr.has_name(sym::rustc_main) && !attr.has_name(sym::start));
221+
item.attrs.push(allow_dead_code);
230222
}
231-
EntryPointType::None | EntryPointType::OtherMain => item,
223+
EntryPointType::None | EntryPointType::OtherMain => {}
232224
};
233-
234-
smallvec![item]
235225
}
236226
}
237227

@@ -292,7 +282,7 @@ fn generate_test_harness(
292282
/// Most of the Ident have the usual def-site hygiene for the AST pass. The
293283
/// exception is the `test_const`s. These have a syntax context that has two
294284
/// opaque marks: one from the expansion of `test` or `test_case`, and one
295-
/// generated in `TestHarnessGenerator::flat_map_item`. When resolving this
285+
/// generated in `TestHarnessGenerator::visit_item`. When resolving this
296286
/// identifier after failing to find a matching identifier in the root module
297287
/// we remove the outer mark, and try resolving at its def-site, which will
298288
/// then resolve to `test_const`.

‎compiler/rustc_expand/src/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ impl InvocationCollectorNode for P<ast::ForeignItem> {
13821382
fragment.make_foreign_items()
13831383
}
13841384
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1385-
walk_flat_map_item(visitor, self)
1385+
walk_flat_map_foreign_item(visitor, self)
13861386
}
13871387
fn is_mac_call(&self) -> bool {
13881388
matches!(self.kind, ForeignItemKind::MacCall(..))

‎compiler/rustc_expand/src/placeholders.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl MutVisitor for PlaceholderExpander {
296296
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
297297
match item.kind {
298298
ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(),
299-
_ => walk_flat_map_item(self, item),
299+
_ => walk_flat_map_foreign_item(self, item),
300300
}
301301
}
302302

‎compiler/rustc_lint/src/early.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,16 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
230230
}
231231

232232
fn visit_assoc_item(&mut self, item: &'a ast::AssocItem, ctxt: ast_visit::AssocCtxt) {
233-
self.with_lint_attrs(item.id, &item.attrs, |cx| match ctxt {
234-
ast_visit::AssocCtxt::Trait => {
235-
lint_callback!(cx, check_trait_item, item);
236-
ast_visit::walk_assoc_item(cx, item, ctxt);
237-
}
238-
ast_visit::AssocCtxt::Impl => {
239-
lint_callback!(cx, check_impl_item, item);
240-
ast_visit::walk_assoc_item(cx, item, ctxt);
233+
self.with_lint_attrs(item.id, &item.attrs, |cx| {
234+
match ctxt {
235+
ast_visit::AssocCtxt::Trait => {
236+
lint_callback!(cx, check_trait_item, item);
237+
}
238+
ast_visit::AssocCtxt::Impl => {
239+
lint_callback!(cx, check_impl_item, item);
240+
}
241241
}
242+
ast_visit::walk_assoc_item(cx, item, ctxt);
242243
});
243244
}
244245

0 commit comments

Comments
 (0)
This repository has been archived.