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 e58bcf0

Browse files
committedJul 22, 2024
Auto merge of rust-lang#127524 - oli-obk:feed_item_attrs2, r=<try>
Make ast `MutVisitor` have the same method name and style as `Visitor` It doesn't map 100% because some `MutVisitor` methods can filter or even expand to multiple items, but consistency seems nicer. tracking issue: rust-lang#127615
2 parents aee3dc4 + e9f32d0 commit e58bcf0

File tree

12 files changed

+478
-445
lines changed

12 files changed

+478
-445
lines changed
 

‎compiler/rustc_ast/src/mut_visit.rs‎

Lines changed: 298 additions & 273 deletions
Large diffs are not rendered by default.

‎compiler/rustc_builtin_macros/src/cfg_eval.rs‎

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::ops::ControlFlow;
44
use rustc_ast as ast;
55
use rustc_ast::mut_visit::MutVisitor;
66
use rustc_ast::ptr::P;
7-
use rustc_ast::visit::Visitor;
7+
use rustc_ast::visit::{AssocCtxt, Visitor};
88
use rustc_ast::NodeId;
99
use rustc_ast::{mut_visit, visit};
1010
use rustc_ast::{Attribute, HasAttrs, HasTokens};
@@ -53,11 +53,8 @@ fn flat_map_annotatable(
5353
) -> Option<Annotatable> {
5454
match annotatable {
5555
Annotatable::Item(item) => vis.flat_map_item(item).pop().map(Annotatable::Item),
56-
Annotatable::TraitItem(item) => {
57-
vis.flat_map_trait_item(item).pop().map(Annotatable::TraitItem)
58-
}
59-
Annotatable::ImplItem(item) => {
60-
vis.flat_map_impl_item(item).pop().map(Annotatable::ImplItem)
56+
Annotatable::AssocItem(item, ctxt) => {
57+
Some(Annotatable::AssocItem(vis.flat_map_assoc_item(item, ctxt).pop()?, ctxt))
6158
}
6259
Annotatable::ForeignItem(item) => {
6360
vis.flat_map_foreign_item(item).pop().map(Annotatable::ForeignItem)
@@ -106,8 +103,7 @@ fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool {
106103

107104
let res = match annotatable {
108105
Annotatable::Item(item) => CfgFinder.visit_item(item),
109-
Annotatable::TraitItem(item) => CfgFinder.visit_assoc_item(item, visit::AssocCtxt::Trait),
110-
Annotatable::ImplItem(item) => CfgFinder.visit_assoc_item(item, visit::AssocCtxt::Impl),
106+
Annotatable::AssocItem(item, ctxt) => CfgFinder.visit_assoc_item(item, *ctxt),
111107
Annotatable::ForeignItem(item) => CfgFinder.visit_foreign_item(item),
112108
Annotatable::Stmt(stmt) => CfgFinder.visit_stmt(stmt),
113109
Annotatable::Expr(expr) => CfgFinder.visit_expr(expr),
@@ -150,14 +146,16 @@ impl CfgEval<'_> {
150146
Annotatable::Item(_) => {
151147
|parser| Ok(Annotatable::Item(parser.parse_item(ForceCollect::Yes)?.unwrap()))
152148
}
153-
Annotatable::TraitItem(_) => |parser| {
154-
Ok(Annotatable::TraitItem(
149+
Annotatable::AssocItem(_, AssocCtxt::Trait) => |parser| {
150+
Ok(Annotatable::AssocItem(
155151
parser.parse_trait_item(ForceCollect::Yes)?.unwrap().unwrap(),
152+
AssocCtxt::Trait,
156153
))
157154
},
158-
Annotatable::ImplItem(_) => |parser| {
159-
Ok(Annotatable::ImplItem(
155+
Annotatable::AssocItem(_, AssocCtxt::Impl) => |parser| {
156+
Ok(Annotatable::AssocItem(
160157
parser.parse_impl_item(ForceCollect::Yes)?.unwrap().unwrap(),
158+
AssocCtxt::Impl,
161159
))
162160
},
163161
Annotatable::ForeignItem(_) => |parser| {
@@ -214,72 +212,83 @@ impl MutVisitor for CfgEval<'_> {
214212
#[instrument(level = "trace", skip(self))]
215213
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
216214
self.0.configure_expr(expr, false);
217-
mut_visit::noop_visit_expr(expr, self);
215+
mut_visit::walk_expr(self, expr);
218216
}
219217

220218
#[instrument(level = "trace", skip(self))]
221219
fn visit_method_receiver_expr(&mut self, expr: &mut P<ast::Expr>) {
222220
self.0.configure_expr(expr, true);
223-
mut_visit::noop_visit_expr(expr, self);
221+
mut_visit::walk_expr(self, expr);
224222
}
225223

226224
fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
227225
let mut expr = configure!(self, expr);
228-
mut_visit::noop_visit_expr(&mut expr, self);
226+
mut_visit::walk_expr(self, &mut expr);
229227
Some(expr)
230228
}
231229

232230
fn flat_map_generic_param(
233231
&mut self,
234232
param: ast::GenericParam,
235233
) -> SmallVec<[ast::GenericParam; 1]> {
236-
mut_visit::noop_flat_map_generic_param(configure!(self, param), self)
234+
let param = configure!(self, param);
235+
mut_visit::walk_flat_map_generic_param(self, param)
237236
}
238237

239238
fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
240-
mut_visit::noop_flat_map_stmt(configure!(self, stmt), self)
239+
let stmt = configure!(self, stmt);
240+
mut_visit::walk_flat_map_stmt(self, stmt)
241241
}
242242

243243
fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
244-
mut_visit::noop_flat_map_item(configure!(self, item), self)
245-
}
246-
247-
fn flat_map_impl_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
248-
mut_visit::noop_flat_map_item(configure!(self, item), self)
244+
let item = configure!(self, item);
245+
mut_visit::walk_flat_map_item(self, item)
249246
}
250247

251-
fn flat_map_trait_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
252-
mut_visit::noop_flat_map_item(configure!(self, item), self)
248+
fn flat_map_assoc_item(
249+
&mut self,
250+
item: P<ast::AssocItem>,
251+
_ctxt: AssocCtxt,
252+
) -> SmallVec<[P<ast::AssocItem>; 1]> {
253+
let item = configure!(self, item);
254+
mut_visit::walk_flat_map_item(self, item)
253255
}
254256

255257
fn flat_map_foreign_item(
256258
&mut self,
257259
foreign_item: P<ast::ForeignItem>,
258260
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
259-
mut_visit::noop_flat_map_item(configure!(self, foreign_item), self)
261+
let foreign_item = configure!(self, foreign_item);
262+
mut_visit::walk_flat_map_item(self, foreign_item)
260263
}
261264

262265
fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> {
263-
mut_visit::noop_flat_map_arm(configure!(self, arm), self)
266+
let arm = configure!(self, arm);
267+
mut_visit::walk_flat_map_arm(self, arm)
264268
}
265269

266270
fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> {
267-
mut_visit::noop_flat_map_expr_field(configure!(self, field), self)
271+
let field = configure!(self, field);
272+
mut_visit::walk_flat_map_expr_field(self, field)
268273
}
269274

270275
fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> {
271-
mut_visit::noop_flat_map_pat_field(configure!(self, fp), self)
276+
let fp = configure!(self, fp);
277+
mut_visit::walk_flat_map_pat_field(self, fp)
272278
}
273279

274280
fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> {
275-
mut_visit::noop_flat_map_param(configure!(self, p), self)
281+
let p = configure!(self, p);
282+
mut_visit::walk_flat_map_param(self, p)
276283
}
277284

278285
fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> {
279-
mut_visit::noop_flat_map_field_def(configure!(self, sf), self)
286+
let sf = configure!(self, sf);
287+
mut_visit::walk_flat_map_field_def(self, sf)
280288
}
281289

282290
fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> {
283-
mut_visit::noop_flat_map_variant(configure!(self, variant), self)
291+
let variant = configure!(self, variant);
292+
mut_visit::walk_flat_map_variant(self, variant)
284293
}
285294
}

‎compiler/rustc_builtin_macros/src/test_harness.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ 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-
noop_visit_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
129129
c.items.push(mk_main(&mut self.cx));
130130
}
131131

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

@@ -144,13 +144,13 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
144144
item.kind
145145
{
146146
let prev_tests = mem::take(&mut self.tests);
147-
noop_visit_item_kind(&mut item.kind, self);
147+
walk_item_kind(&mut item.kind, item.span, item.id, self);
148148
self.add_test_cases(item.id, span, prev_tests);
149149
} else {
150150
// But in those cases, we emit a lint to warn the user of these missing tests.
151151
walk_item(&mut InnerItemLinter { sess: self.cx.ext_cx.sess }, &item);
152152
}
153-
smallvec![P(item)]
153+
smallvec![i]
154154
}
155155
}
156156

@@ -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 = noop_flat_map_item(i, self).expect_one("noop did something");
195+
let item = walk_flat_map_item(self, i).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_builtin_macros/src/util.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ pub(crate) fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaI
2727
pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable, name: Symbol) {
2828
let attrs: Option<&[Attribute]> = match item {
2929
Annotatable::Item(item) => Some(&item.attrs),
30-
Annotatable::TraitItem(item) => Some(&item.attrs),
31-
Annotatable::ImplItem(item) => Some(&item.attrs),
30+
Annotatable::AssocItem(item, _) => Some(&item.attrs),
3231
Annotatable::ForeignItem(item) => Some(&item.attrs),
3332
Annotatable::Expr(expr) => Some(&expr.attrs),
3433
Annotatable::Arm(arm) => Some(&arm.attrs),

‎compiler/rustc_expand/src/base.rs‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ use thin_vec::ThinVec;
3737
#[derive(Debug, Clone)]
3838
pub enum Annotatable {
3939
Item(P<ast::Item>),
40-
TraitItem(P<ast::AssocItem>),
41-
ImplItem(P<ast::AssocItem>),
40+
AssocItem(P<ast::AssocItem>, AssocCtxt),
4241
ForeignItem(P<ast::ForeignItem>),
4342
Stmt(P<ast::Stmt>),
4443
Expr(P<ast::Expr>),
@@ -56,8 +55,7 @@ impl Annotatable {
5655
pub fn span(&self) -> Span {
5756
match self {
5857
Annotatable::Item(item) => item.span,
59-
Annotatable::TraitItem(trait_item) => trait_item.span,
60-
Annotatable::ImplItem(impl_item) => impl_item.span,
58+
Annotatable::AssocItem(assoc_item, _) => assoc_item.span,
6159
Annotatable::ForeignItem(foreign_item) => foreign_item.span,
6260
Annotatable::Stmt(stmt) => stmt.span,
6361
Annotatable::Expr(expr) => expr.span,
@@ -75,8 +73,7 @@ impl Annotatable {
7573
pub fn visit_attrs(&mut self, f: impl FnOnce(&mut AttrVec)) {
7674
match self {
7775
Annotatable::Item(item) => item.visit_attrs(f),
78-
Annotatable::TraitItem(trait_item) => trait_item.visit_attrs(f),
79-
Annotatable::ImplItem(impl_item) => impl_item.visit_attrs(f),
76+
Annotatable::AssocItem(assoc_item, _) => assoc_item.visit_attrs(f),
8077
Annotatable::ForeignItem(foreign_item) => foreign_item.visit_attrs(f),
8178
Annotatable::Stmt(stmt) => stmt.visit_attrs(f),
8279
Annotatable::Expr(expr) => expr.visit_attrs(f),
@@ -94,8 +91,7 @@ impl Annotatable {
9491
pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) -> V::Result {
9592
match self {
9693
Annotatable::Item(item) => visitor.visit_item(item),
97-
Annotatable::TraitItem(item) => visitor.visit_assoc_item(item, AssocCtxt::Trait),
98-
Annotatable::ImplItem(item) => visitor.visit_assoc_item(item, AssocCtxt::Impl),
94+
Annotatable::AssocItem(item, ctxt) => visitor.visit_assoc_item(item, *ctxt),
9995
Annotatable::ForeignItem(foreign_item) => visitor.visit_foreign_item(foreign_item),
10096
Annotatable::Stmt(stmt) => visitor.visit_stmt(stmt),
10197
Annotatable::Expr(expr) => visitor.visit_expr(expr),
@@ -113,9 +109,7 @@ impl Annotatable {
113109
pub fn to_tokens(&self) -> TokenStream {
114110
match self {
115111
Annotatable::Item(node) => TokenStream::from_ast(node),
116-
Annotatable::TraitItem(node) | Annotatable::ImplItem(node) => {
117-
TokenStream::from_ast(node)
118-
}
112+
Annotatable::AssocItem(node, _) => TokenStream::from_ast(node),
119113
Annotatable::ForeignItem(node) => TokenStream::from_ast(node),
120114
Annotatable::Stmt(node) => {
121115
assert!(!matches!(node.kind, ast::StmtKind::Empty));
@@ -142,14 +136,14 @@ impl Annotatable {
142136

143137
pub fn expect_trait_item(self) -> P<ast::AssocItem> {
144138
match self {
145-
Annotatable::TraitItem(i) => i,
139+
Annotatable::AssocItem(i, AssocCtxt::Trait) => i,
146140
_ => panic!("expected Item"),
147141
}
148142
}
149143

150144
pub fn expect_impl_item(self) -> P<ast::AssocItem> {
151145
match self {
152-
Annotatable::ImplItem(i) => i,
146+
Annotatable::AssocItem(i, AssocCtxt::Impl) => i,
153147
_ => panic!("expected Item"),
154148
}
155149
}

‎compiler/rustc_expand/src/expand.rs‎

Lines changed: 72 additions & 70 deletions
Large diffs are not rendered by default.

‎compiler/rustc_expand/src/mbe/transcribe.rs‎

Lines changed: 2 additions & 2 deletions
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
}

‎compiler/rustc_expand/src/placeholders.rs‎

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::expand::{AstFragment, AstFragmentKind};
2-
use rustc_ast as ast;
32
use rustc_ast::mut_visit::*;
43
use rustc_ast::ptr::P;
54
use rustc_ast::token::Delimiter;
5+
use rustc_ast::{self as ast, visit::AssocCtxt};
66
use rustc_data_structures::fx::FxHashMap;
77
use rustc_span::symbol::Ident;
88
use rustc_span::DUMMY_SP;
@@ -209,23 +209,23 @@ impl MutVisitor for PlaceholderExpander {
209209
if arm.is_placeholder {
210210
self.remove(arm.id).make_arms()
211211
} else {
212-
noop_flat_map_arm(arm, self)
212+
walk_flat_map_arm(self, arm)
213213
}
214214
}
215215

216216
fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> {
217217
if field.is_placeholder {
218218
self.remove(field.id).make_expr_fields()
219219
} else {
220-
noop_flat_map_expr_field(field, self)
220+
walk_flat_map_expr_field(self, field)
221221
}
222222
}
223223

224224
fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> {
225225
if fp.is_placeholder {
226226
self.remove(fp.id).make_pat_fields()
227227
} else {
228-
noop_flat_map_pat_field(fp, self)
228+
walk_flat_map_pat_field(self, fp)
229229
}
230230
}
231231

@@ -236,52 +236,55 @@ impl MutVisitor for PlaceholderExpander {
236236
if param.is_placeholder {
237237
self.remove(param.id).make_generic_params()
238238
} else {
239-
noop_flat_map_generic_param(param, self)
239+
walk_flat_map_generic_param(self, param)
240240
}
241241
}
242242

243243
fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> {
244244
if p.is_placeholder {
245245
self.remove(p.id).make_params()
246246
} else {
247-
noop_flat_map_param(p, self)
247+
walk_flat_map_param(self, p)
248248
}
249249
}
250250

251251
fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> {
252252
if sf.is_placeholder {
253253
self.remove(sf.id).make_field_defs()
254254
} else {
255-
noop_flat_map_field_def(sf, self)
255+
walk_flat_map_field_def(self, sf)
256256
}
257257
}
258258

259259
fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> {
260260
if variant.is_placeholder {
261261
self.remove(variant.id).make_variants()
262262
} else {
263-
noop_flat_map_variant(variant, self)
263+
walk_flat_map_variant(self, variant)
264264
}
265265
}
266266

267267
fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
268268
match item.kind {
269269
ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(),
270-
_ => noop_flat_map_item(item, self),
270+
_ => walk_flat_map_item(self, item),
271271
}
272272
}
273273

274-
fn flat_map_trait_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
275-
match item.kind {
276-
ast::AssocItemKind::MacCall(_) => self.remove(item.id).make_trait_items(),
277-
_ => noop_flat_map_item(item, self),
278-
}
279-
}
280-
281-
fn flat_map_impl_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
274+
fn flat_map_assoc_item(
275+
&mut self,
276+
item: P<ast::AssocItem>,
277+
ctxt: AssocCtxt,
278+
) -> SmallVec<[P<ast::AssocItem>; 1]> {
282279
match item.kind {
283-
ast::AssocItemKind::MacCall(_) => self.remove(item.id).make_impl_items(),
284-
_ => noop_flat_map_item(item, self),
280+
ast::AssocItemKind::MacCall(_) => {
281+
let it = self.remove(item.id);
282+
match ctxt {
283+
AssocCtxt::Trait => it.make_trait_items(),
284+
AssocCtxt::Impl => it.make_impl_items(),
285+
}
286+
}
287+
_ => walk_flat_map_item(self, item),
285288
}
286289
}
287290

@@ -291,35 +294,35 @@ impl MutVisitor for PlaceholderExpander {
291294
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
292295
match item.kind {
293296
ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(),
294-
_ => noop_flat_map_item(item, self),
297+
_ => walk_flat_map_item(self, item),
295298
}
296299
}
297300

298301
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
299302
match expr.kind {
300303
ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_expr(),
301-
_ => noop_visit_expr(expr, self),
304+
_ => walk_expr(self, expr),
302305
}
303306
}
304307

305308
fn visit_method_receiver_expr(&mut self, expr: &mut P<ast::Expr>) {
306309
match expr.kind {
307310
ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_method_receiver_expr(),
308-
_ => noop_visit_expr(expr, self),
311+
_ => walk_expr(self, expr),
309312
}
310313
}
311314

312315
fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
313316
match expr.kind {
314317
ast::ExprKind::MacCall(_) => self.remove(expr.id).make_opt_expr(),
315-
_ => noop_filter_map_expr(expr, self),
318+
_ => noop_filter_map_expr(self, expr),
316319
}
317320
}
318321

319322
fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
320323
let (style, mut stmts) = match stmt.kind {
321324
ast::StmtKind::MacCall(mac) => (mac.style, self.remove(stmt.id).make_stmts()),
322-
_ => return noop_flat_map_stmt(stmt, self),
325+
_ => return walk_flat_map_stmt(self, stmt),
323326
};
324327

325328
if style == ast::MacStmtStyle::Semicolon {
@@ -365,22 +368,22 @@ impl MutVisitor for PlaceholderExpander {
365368
fn visit_pat(&mut self, pat: &mut P<ast::Pat>) {
366369
match pat.kind {
367370
ast::PatKind::MacCall(_) => *pat = self.remove(pat.id).make_pat(),
368-
_ => noop_visit_pat(pat, self),
371+
_ => walk_pat(self, pat),
369372
}
370373
}
371374

372375
fn visit_ty(&mut self, ty: &mut P<ast::Ty>) {
373376
match ty.kind {
374377
ast::TyKind::MacCall(_) => *ty = self.remove(ty.id).make_ty(),
375-
_ => noop_visit_ty(ty, self),
378+
_ => walk_ty(self, ty),
376379
}
377380
}
378381

379382
fn visit_crate(&mut self, krate: &mut ast::Crate) {
380383
if krate.is_placeholder {
381384
*krate = self.remove(krate.id).make_crate();
382385
} else {
383-
noop_visit_crate(krate, self)
386+
walk_crate(self, krate)
384387
}
385388
}
386389
}

‎compiler/rustc_parse/src/parser/expr.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use super::{
1010

1111
use crate::errors;
1212
use crate::maybe_recover_from_interpolated_ty_qpath;
13-
use ast::mut_visit::{noop_visit_expr, MutVisitor};
13+
use ast::mut_visit::{self, MutVisitor};
1414
use ast::token::IdentIsRaw;
1515
use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment, Recovered};
1616
use core::mem;
@@ -3939,22 +3939,22 @@ impl MutVisitor for CondChecker<'_> {
39393939
}
39403940
}
39413941
ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, _, _) => {
3942-
noop_visit_expr(e, self);
3942+
mut_visit::walk_expr(self, e);
39433943
}
39443944
ExprKind::Binary(Spanned { node: BinOpKind::Or, span: or_span }, _, _)
39453945
if let None | Some(NotSupportedOr(_)) = self.forbid_let_reason =>
39463946
{
39473947
let forbid_let_reason = self.forbid_let_reason;
39483948
self.forbid_let_reason = Some(NotSupportedOr(or_span));
3949-
noop_visit_expr(e, self);
3949+
mut_visit::walk_expr(self, e);
39503950
self.forbid_let_reason = forbid_let_reason;
39513951
}
39523952
ExprKind::Paren(ref inner)
39533953
if let None | Some(NotSupportedParentheses(_)) = self.forbid_let_reason =>
39543954
{
39553955
let forbid_let_reason = self.forbid_let_reason;
39563956
self.forbid_let_reason = Some(NotSupportedParentheses(inner.span));
3957-
noop_visit_expr(e, self);
3957+
mut_visit::walk_expr(self, e);
39583958
self.forbid_let_reason = forbid_let_reason;
39593959
}
39603960
ExprKind::Assign(ref lhs, _, span) => {
@@ -3972,7 +3972,7 @@ impl MutVisitor for CondChecker<'_> {
39723972
}
39733973
let comparison = self.comparison;
39743974
self.comparison = Some(errors::MaybeComparison { span: span.shrink_to_hi() });
3975-
noop_visit_expr(e, self);
3975+
mut_visit::walk_expr(self, e);
39763976
self.forbid_let_reason = forbid_let_reason;
39773977
self.missing_let = missing_let;
39783978
self.comparison = comparison;
@@ -3992,7 +3992,7 @@ impl MutVisitor for CondChecker<'_> {
39923992
| ExprKind::Paren(_) => {
39933993
let forbid_let_reason = self.forbid_let_reason;
39943994
self.forbid_let_reason = Some(OtherForbidden);
3995-
noop_visit_expr(e, self);
3995+
mut_visit::walk_expr(self, e);
39963996
self.forbid_let_reason = forbid_let_reason;
39973997
}
39983998
ExprKind::Cast(ref mut op, _) | ExprKind::Type(ref mut op, _) => {

‎compiler/rustc_parse/src/parser/pat.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::errors::{
1212
};
1313
use crate::parser::expr::{could_be_unclosed_char_literal, LhsExpr};
1414
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
15-
use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor};
15+
use rustc_ast::mut_visit::{walk_pat, MutVisitor};
1616
use rustc_ast::ptr::P;
1717
use rustc_ast::token::{self, BinOpToken, Delimiter, Token};
1818
use rustc_ast::{
@@ -810,7 +810,7 @@ impl<'a> Parser<'a> {
810810
self.0 = true;
811811
*m = Mutability::Mut;
812812
}
813-
noop_visit_pat(pat, self);
813+
walk_pat(self, pat);
814814
}
815815
}
816816

‎src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn remove_all_parens(pat: &mut P<Pat>) {
121121
struct Visitor;
122122
impl MutVisitor for Visitor {
123123
fn visit_pat(&mut self, pat: &mut P<Pat>) {
124-
noop_visit_pat(pat, self);
124+
walk_pat(self, pat);
125125
let inner = match &mut pat.kind {
126126
Paren(i) => mem::replace(&mut i.kind, Wild),
127127
_ => return,
@@ -138,7 +138,7 @@ fn insert_necessary_parens(pat: &mut P<Pat>) {
138138
impl MutVisitor for Visitor {
139139
fn visit_pat(&mut self, pat: &mut P<Pat>) {
140140
use ast::BindingMode;
141-
noop_visit_pat(pat, self);
141+
walk_pat(self, pat);
142142
let target = match &mut pat.kind {
143143
// `i @ a | b`, `box a | b`, and `& mut? a | b`.
144144
Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p,
@@ -160,7 +160,7 @@ fn unnest_or_patterns(pat: &mut P<Pat>) -> bool {
160160
impl MutVisitor for Visitor {
161161
fn visit_pat(&mut self, p: &mut P<Pat>) {
162162
// This is a bottom up transformation, so recurse first.
163-
noop_visit_pat(p, self);
163+
walk_pat(self, p);
164164

165165
// Don't have an or-pattern? Just quit early on.
166166
let Or(alternatives) = &mut p.kind else { return };
@@ -189,7 +189,7 @@ fn unnest_or_patterns(pat: &mut P<Pat>) -> bool {
189189

190190
// Deal with `Some(Some(0)) | Some(Some(1))`.
191191
if this_level_changed {
192-
noop_visit_pat(p, self);
192+
walk_pat(self, p);
193193
}
194194
}
195195
}

‎tests/ui-fulldeps/pprust-expr-roundtrip.rs‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ use thin_vec::{thin_vec, ThinVec};
4646
fn parse_expr(psess: &ParseSess, src: &str) -> Option<P<Expr>> {
4747
let src_as_string = src.to_string();
4848

49-
let mut p = unwrap_or_emit_fatal(
50-
new_parser_from_source_str(psess, FileName::Custom(src_as_string.clone()), src_as_string)
51-
);
49+
let mut p = unwrap_or_emit_fatal(new_parser_from_source_str(
50+
psess,
51+
FileName::Custom(src_as_string.clone()),
52+
src_as_string,
53+
));
5254
p.parse_expr().map_err(|e| e.cancel()).ok()
5355
}
5456

@@ -181,10 +183,9 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
181183
18 => {
182184
let pat =
183185
P(Pat { id: DUMMY_NODE_ID, kind: PatKind::Wild, span: DUMMY_SP, tokens: None });
184-
iter_exprs(
185-
depth - 1,
186-
&mut |e| g(ExprKind::Let(pat.clone(), e, DUMMY_SP, Recovered::No))
187-
)
186+
iter_exprs(depth - 1, &mut |e| {
187+
g(ExprKind::Let(pat.clone(), e, DUMMY_SP, Recovered::No))
188+
})
188189
}
189190
_ => panic!("bad counter value in iter_exprs"),
190191
}
@@ -202,7 +203,7 @@ impl MutVisitor for RemoveParens {
202203
ExprKind::Paren(inner) => *e = inner,
203204
_ => {}
204205
};
205-
mut_visit::noop_visit_expr(e, self);
206+
mut_visit::walk_expr(self, e);
206207
}
207208
}
208209

@@ -211,7 +212,7 @@ struct AddParens;
211212

212213
impl MutVisitor for AddParens {
213214
fn visit_expr(&mut self, e: &mut P<Expr>) {
214-
mut_visit::noop_visit_expr(e, self);
215+
mut_visit::walk_expr(self, e);
215216
visit_clobber(e, |e| {
216217
P(Expr {
217218
id: DUMMY_NODE_ID,

0 commit comments

Comments
 (0)
This repository has been archived.