Skip to content

Commit 8d29005

Browse files
committed
Always pass the visitor as the first argument to walk* functions
1 parent 754bdef commit 8d29005

File tree

10 files changed

+294
-282
lines changed

10 files changed

+294
-282
lines changed

compiler/rustc_ast/src/mut_visit.rs

+207-207
Large diffs are not rendered by default.

compiler/rustc_builtin_macros/src/cfg_eval.rs

+25-14
Original file line numberDiff line numberDiff line change
@@ -212,72 +212,83 @@ impl MutVisitor for CfgEval<'_> {
212212
#[instrument(level = "trace", skip(self))]
213213
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
214214
self.0.configure_expr(expr, false);
215-
mut_visit::walk_expr(expr, self);
215+
mut_visit::walk_expr(self, expr);
216216
}
217217

218218
#[instrument(level = "trace", skip(self))]
219219
fn visit_method_receiver_expr(&mut self, expr: &mut P<ast::Expr>) {
220220
self.0.configure_expr(expr, true);
221-
mut_visit::walk_expr(expr, self);
221+
mut_visit::walk_expr(self, expr);
222222
}
223223

224224
fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
225225
let mut expr = configure!(self, expr);
226-
mut_visit::walk_expr(&mut expr, self);
226+
mut_visit::walk_expr(self, &mut expr);
227227
Some(expr)
228228
}
229229

230230
fn flat_map_generic_param(
231231
&mut self,
232232
param: ast::GenericParam,
233233
) -> SmallVec<[ast::GenericParam; 1]> {
234-
mut_visit::walk_flat_map_generic_param(configure!(self, param), self)
234+
let param = configure!(self, param);
235+
mut_visit::walk_flat_map_generic_param(self, param)
235236
}
236237

237238
fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
238-
mut_visit::walk_flat_map_stmt(configure!(self, stmt), self)
239+
let stmt = configure!(self, stmt);
240+
mut_visit::walk_flat_map_stmt(self, stmt)
239241
}
240242

241243
fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
242-
mut_visit::walk_flat_map_item(configure!(self, item), None, self)
244+
let item = configure!(self, item);
245+
mut_visit::walk_flat_map_item(self, item, None)
243246
}
244247

245248
fn flat_map_assoc_item(
246249
&mut self,
247250
item: P<ast::AssocItem>,
248251
ctxt: AssocCtxt,
249252
) -> SmallVec<[P<ast::AssocItem>; 1]> {
250-
mut_visit::walk_flat_map_item(configure!(self, item), Some(ctxt), self)
253+
let item = configure!(self, item);
254+
mut_visit::walk_flat_map_item(self, item, Some(ctxt))
251255
}
252256

253257
fn flat_map_foreign_item(
254258
&mut self,
255259
foreign_item: P<ast::ForeignItem>,
256260
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
257-
mut_visit::walk_flat_map_item(configure!(self, foreign_item), None, self)
261+
let foreign_item = configure!(self, foreign_item);
262+
mut_visit::walk_flat_map_item(self, foreign_item, None)
258263
}
259264

260265
fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> {
261-
mut_visit::walk_flat_map_arm(configure!(self, arm), self)
266+
let arm = configure!(self, arm);
267+
mut_visit::walk_flat_map_arm(self, arm)
262268
}
263269

264270
fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> {
265-
mut_visit::walk_flat_map_expr_field(configure!(self, field), self)
271+
let field = configure!(self, field);
272+
mut_visit::walk_flat_map_expr_field(self, field)
266273
}
267274

268275
fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> {
269-
mut_visit::walk_flat_map_pat_field(configure!(self, fp), self)
276+
let fp = configure!(self, fp);
277+
mut_visit::walk_flat_map_pat_field(self, fp)
270278
}
271279

272280
fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> {
273-
mut_visit::walk_flat_map_param(configure!(self, p), self)
281+
let p = configure!(self, p);
282+
mut_visit::walk_flat_map_param(self, p)
274283
}
275284

276285
fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> {
277-
mut_visit::walk_flat_map_field_def(configure!(self, sf), self)
286+
let sf = configure!(self, sf);
287+
mut_visit::walk_flat_map_field_def(self, sf)
278288
}
279289

280290
fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> {
281-
mut_visit::walk_flat_map_variant(configure!(self, variant), self)
291+
let variant = configure!(self, variant);
292+
mut_visit::walk_flat_map_variant(self, variant)
282293
}
283294
}

compiler/rustc_builtin_macros/src/test_harness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl TestHarnessGenerator<'_> {
122122
impl<'a> MutVisitor for TestHarnessGenerator<'a> {
123123
fn visit_crate(&mut self, c: &mut ast::Crate) {
124124
let prev_tests = mem::take(&mut self.tests);
125-
walk_crate(c, self);
125+
walk_crate(self, c);
126126
self.add_test_cases(ast::CRATE_NODE_ID, c.spans.inner_span, prev_tests);
127127

128128
// Create a main function to run our tests
@@ -192,7 +192,7 @@ struct EntryPointCleaner<'a> {
192192
impl<'a> MutVisitor for EntryPointCleaner<'a> {
193193
fn flat_map_item(&mut self, i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
194194
self.depth += 1;
195-
let item = walk_flat_map_item(i, None, self).expect_one("noop did something");
195+
let item = walk_flat_map_item(self, i, None).expect_one("noop did something");
196196
self.depth -= 1;
197197

198198
// Remove any #[rustc_main] or #[start] from the AST so it doesn't

compiler/rustc_expand/src/expand.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ impl InvocationCollectorNode for P<ast::Item> {
11491149
fragment.make_items()
11501150
}
11511151
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1152-
walk_flat_map_item(self, None, visitor)
1152+
walk_flat_map_item(visitor, self, None)
11531153
}
11541154
fn is_mac_call(&self) -> bool {
11551155
matches!(self.kind, ItemKind::MacCall(..))
@@ -1293,7 +1293,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag>
12931293
fragment.make_trait_items()
12941294
}
12951295
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1296-
walk_flat_map_item(self.wrapped, Some(AssocCtxt::Trait), visitor)
1296+
walk_flat_map_item(visitor, self.wrapped, Some(AssocCtxt::Trait))
12971297
}
12981298
fn is_mac_call(&self) -> bool {
12991299
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
@@ -1334,7 +1334,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag>
13341334
fragment.make_impl_items()
13351335
}
13361336
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1337-
walk_flat_map_item(self.wrapped, Some(AssocCtxt::Impl), visitor)
1337+
walk_flat_map_item(visitor, self.wrapped, Some(AssocCtxt::Impl))
13381338
}
13391339
fn is_mac_call(&self) -> bool {
13401340
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
@@ -1372,7 +1372,7 @@ impl InvocationCollectorNode for P<ast::ForeignItem> {
13721372
fragment.make_foreign_items()
13731373
}
13741374
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1375-
walk_flat_map_item(self, None, visitor)
1375+
walk_flat_map_item(visitor, self, None)
13761376
}
13771377
fn is_mac_call(&self) -> bool {
13781378
matches!(self.kind, ForeignItemKind::MacCall(..))
@@ -1395,7 +1395,7 @@ impl InvocationCollectorNode for ast::Variant {
13951395
fragment.make_variants()
13961396
}
13971397
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1398-
walk_flat_map_variant(self, visitor)
1398+
walk_flat_map_variant(visitor, self)
13991399
}
14001400
}
14011401

@@ -1408,7 +1408,7 @@ impl InvocationCollectorNode for ast::FieldDef {
14081408
fragment.make_field_defs()
14091409
}
14101410
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1411-
walk_flat_map_field_def(self, visitor)
1411+
walk_flat_map_field_def(visitor, self)
14121412
}
14131413
}
14141414

@@ -1421,7 +1421,7 @@ impl InvocationCollectorNode for ast::PatField {
14211421
fragment.make_pat_fields()
14221422
}
14231423
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1424-
walk_flat_map_pat_field(self, visitor)
1424+
walk_flat_map_pat_field(visitor, self)
14251425
}
14261426
}
14271427

@@ -1434,7 +1434,7 @@ impl InvocationCollectorNode for ast::ExprField {
14341434
fragment.make_expr_fields()
14351435
}
14361436
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1437-
walk_flat_map_expr_field(self, visitor)
1437+
walk_flat_map_expr_field(visitor, self)
14381438
}
14391439
}
14401440

@@ -1447,7 +1447,7 @@ impl InvocationCollectorNode for ast::Param {
14471447
fragment.make_params()
14481448
}
14491449
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1450-
walk_flat_map_param(self, visitor)
1450+
walk_flat_map_param(visitor, self)
14511451
}
14521452
}
14531453

@@ -1460,7 +1460,7 @@ impl InvocationCollectorNode for ast::GenericParam {
14601460
fragment.make_generic_params()
14611461
}
14621462
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1463-
walk_flat_map_generic_param(self, visitor)
1463+
walk_flat_map_generic_param(visitor, self)
14641464
}
14651465
}
14661466

@@ -1473,7 +1473,7 @@ impl InvocationCollectorNode for ast::Arm {
14731473
fragment.make_arms()
14741474
}
14751475
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1476-
walk_flat_map_arm(self, visitor)
1476+
walk_flat_map_arm(visitor, self)
14771477
}
14781478
}
14791479

@@ -1487,7 +1487,7 @@ impl InvocationCollectorNode for ast::Stmt {
14871487
fragment.make_stmts()
14881488
}
14891489
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
1490-
walk_flat_map_stmt(self, visitor)
1490+
walk_flat_map_stmt(visitor, self)
14911491
}
14921492
fn is_mac_call(&self) -> bool {
14931493
match &self.kind {
@@ -1561,7 +1561,7 @@ impl InvocationCollectorNode for ast::Crate {
15611561
fragment.make_crate()
15621562
}
15631563
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
1564-
walk_crate(self, visitor)
1564+
walk_crate(visitor, self)
15651565
}
15661566
fn expand_cfg_false(
15671567
&mut self,
@@ -1587,7 +1587,7 @@ impl InvocationCollectorNode for P<ast::Ty> {
15871587
fragment.make_ty()
15881588
}
15891589
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
1590-
walk_ty(self, visitor)
1590+
walk_ty(visitor, self)
15911591
}
15921592
fn is_mac_call(&self) -> bool {
15931593
matches!(self.kind, ast::TyKind::MacCall(..))
@@ -1611,7 +1611,7 @@ impl InvocationCollectorNode for P<ast::Pat> {
16111611
fragment.make_pat()
16121612
}
16131613
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
1614-
walk_pat(self, visitor)
1614+
walk_pat(visitor, self)
16151615
}
16161616
fn is_mac_call(&self) -> bool {
16171617
matches!(self.kind, PatKind::MacCall(..))
@@ -1639,7 +1639,7 @@ impl InvocationCollectorNode for P<ast::Expr> {
16391639
"an expression"
16401640
}
16411641
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
1642-
walk_expr(self, visitor)
1642+
walk_expr(visitor, self)
16431643
}
16441644
fn is_mac_call(&self) -> bool {
16451645
matches!(self.kind, ExprKind::MacCall(..))
@@ -1665,7 +1665,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> {
16651665
fragment.make_opt_expr()
16661666
}
16671667
fn walk_flat_map<V: MutVisitor>(mut self, visitor: &mut V) -> Self::OutputTy {
1668-
walk_expr(&mut self.wrapped, visitor);
1668+
walk_expr(visitor, &mut self.wrapped);
16691669
Some(self.wrapped)
16701670
}
16711671
fn is_mac_call(&self) -> bool {
@@ -1705,7 +1705,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, MethodReceiverTag>
17051705
AstNodeWrapper::new(fragment.make_method_receiver_expr(), MethodReceiverTag)
17061706
}
17071707
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
1708-
walk_expr(&mut self.wrapped, visitor)
1708+
walk_expr(visitor, &mut self.wrapped)
17091709
}
17101710
fn is_mac_call(&self) -> bool {
17111711
matches!(self.wrapped.kind, ast::ExprKind::MacCall(..))
@@ -2147,11 +2147,11 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
21472147
self.cx.current_expansion.is_trailing_mac = true;
21482148
// Don't use `assign_id` for this statement - it may get removed
21492149
// entirely due to a `#[cfg]` on the contained expression
2150-
let res = walk_flat_map_stmt(node, self);
2150+
let res = walk_flat_map_stmt(self, node);
21512151
self.cx.current_expansion.is_trailing_mac = false;
21522152
res
21532153
}
2154-
_ => walk_flat_map_stmt(node, self),
2154+
_ => walk_flat_map_stmt(self, node),
21552155
};
21562156
}
21572157

@@ -2195,7 +2195,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
21952195
&mut self.cx.current_expansion.dir_ownership,
21962196
DirOwnership::UnownedViaBlock,
21972197
);
2198-
walk_block(node, self);
2198+
walk_block(self, node);
21992199
self.cx.current_expansion.dir_ownership = orig_dir_ownership;
22002200
}
22012201

compiler/rustc_expand/src/mbe/transcribe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub(super) fn transcribe<'a>(
333333
// jump back out of the Delimited, pop the result_stack and add the new results back to
334334
// the previous results (from outside the Delimited).
335335
mbe::TokenTree::Delimited(mut span, spacing, delimited) => {
336-
mut_visit::visit_delim_span(&mut span, &mut marker);
336+
mut_visit::visit_delim_span(&mut marker, &mut span);
337337
stack.push(Frame::new_delimited(delimited, span, *spacing));
338338
result_stack.push(mem::take(&mut result));
339339
}
@@ -342,7 +342,7 @@ pub(super) fn transcribe<'a>(
342342
// preserve syntax context.
343343
mbe::TokenTree::Token(token) => {
344344
let mut token = token.clone();
345-
mut_visit::visit_token(&mut token, &mut marker);
345+
mut_visit::visit_token(&mut marker, &mut token);
346346
let tt = TokenTree::Token(token, Spacing::Alone);
347347
result.push(tt);
348348
}

0 commit comments

Comments
 (0)