Skip to content

Commit 0b1bf71

Browse files
committed
Auto merge of #133280 - matthiaskrgr:rollup-8keusum, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #131736 (Emscripten: link with -sWASM_BIGINT) - #132207 (Store resolution for self and crate root module segments) - #133153 (Add visits to nodes that already have flat_maps in ast::MutVisitor) - #133218 (Implement `~const` item bounds in RPIT) - #133228 (Rewrite `show_md_content_with_pager`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 318f96a + c83b6a3 commit 0b1bf71

File tree

37 files changed

+434
-182
lines changed

37 files changed

+434
-182
lines changed

compiler/rustc_ast/src/mut_visit.rs

+128-38
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

+16-8
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

+1-1
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]> {

0 commit comments

Comments
 (0)