Skip to content

Commit 7acdffb

Browse files
Rollup merge of rust-lang#141563 - nnethercote:rm-noop, r=petrochenkov
Remove out-of-date `noop_*` names. `mut_visit.rs` has a single function with a `noop_` prefix: `noop_filter_map_expr`. This commit renames as `walk_filter_map_expr` which is consistent with other functions in this file. The commit also removes out-of-date comments that refer to `noop_*` methods. r? `@petrochenkov`
2 parents f1371a8 + 89c21f7 commit 7acdffb

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ pub trait MutVisitor: Sized {
4040
// fn flat_map_t(&mut self, t: T) -> SmallVec<[T; 1]>; // rare
4141
// fn filter_map_t(&mut self, t: T) -> Option<T>; // rarest
4242
//
43-
// Any additions to this trait should happen in form of a call to a public
44-
// `noop_*` function that only calls out to the visitor again, not other
45-
// `noop_*` functions. This is a necessary API workaround to the problem of
46-
// not being able to call out to the super default method in an overridden
47-
// default method.
48-
//
4943
// When writing these methods, it is better to use destructuring like this:
5044
//
5145
// fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
@@ -179,7 +173,7 @@ pub trait MutVisitor: Sized {
179173
}
180174

181175
fn filter_map_expr(&mut self, e: P<Expr>) -> Option<P<Expr>> {
182-
noop_filter_map_expr(self, e)
176+
walk_filter_map_expr(self, e)
183177
}
184178

185179
fn visit_generic_arg(&mut self, arg: &mut GenericArg) {
@@ -381,14 +375,11 @@ super::common_visitor_and_walkers!((mut) MutVisitor);
381375
/// Use a map-style function (`FnOnce(T) -> T`) to overwrite a `&mut T`. Useful
382376
/// when using a `flat_map_*` or `filter_map_*` method within a `visit_`
383377
/// method.
384-
//
385-
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
386378
pub fn visit_clobber<T: DummyAstNode>(t: &mut T, f: impl FnOnce(T) -> T) {
387379
let old_t = std::mem::replace(t, T::dummy());
388380
*t = f(old_t);
389381
}
390382

391-
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
392383
#[inline]
393384
fn visit_vec<T, F>(elems: &mut Vec<T>, mut visit_elem: F)
394385
where
@@ -399,7 +390,6 @@ where
399390
}
400391
}
401392

402-
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
403393
#[inline]
404394
fn visit_thin_vec<T, F>(elems: &mut ThinVec<T>, mut visit_elem: F)
405395
where
@@ -410,7 +400,6 @@ where
410400
}
411401
}
412402

413-
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
414403
#[inline]
415404
fn visit_opt<T, F>(opt: &mut Option<T>, mut visit_elem: F)
416405
where
@@ -421,25 +410,21 @@ where
421410
}
422411
}
423412

424-
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
425413
fn visit_attrs<T: MutVisitor>(vis: &mut T, attrs: &mut AttrVec) {
426414
for attr in attrs.iter_mut() {
427415
vis.visit_attribute(attr);
428416
}
429417
}
430418

431-
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
432419
#[allow(unused)]
433420
fn visit_exprs<T: MutVisitor>(vis: &mut T, exprs: &mut Vec<P<Expr>>) {
434421
exprs.flat_map_in_place(|expr| vis.filter_map_expr(expr))
435422
}
436423

437-
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
438424
fn visit_thin_exprs<T: MutVisitor>(vis: &mut T, exprs: &mut ThinVec<P<Expr>>) {
439425
exprs.flat_map_in_place(|expr| vis.filter_map_expr(expr))
440426
}
441427

442-
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
443428
fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
444429
match args {
445430
AttrArgs::Empty => {}
@@ -451,7 +436,6 @@ fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
451436
}
452437
}
453438

454-
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
455439
fn visit_delim_args<T: MutVisitor>(vis: &mut T, args: &mut DelimArgs) {
456440
let DelimArgs { dspan, delim: _, tokens: _ } = args;
457441
let DelimSpan { open, close } = dspan;
@@ -1500,11 +1484,9 @@ pub fn walk_expr<T: MutVisitor>(vis: &mut T, Expr { kind, id, span, attrs, token
15001484
vis.visit_span(span);
15011485
}
15021486

1503-
pub fn noop_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: P<Expr>) -> Option<P<Expr>> {
1504-
Some({
1505-
vis.visit_expr(&mut e);
1506-
e
1507-
})
1487+
pub fn walk_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: P<Expr>) -> Option<P<Expr>> {
1488+
vis.visit_expr(&mut e);
1489+
Some(e)
15081490
}
15091491

15101492
pub fn walk_flat_map_stmt<T: MutVisitor>(

compiler/rustc_expand/src/placeholders.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl MutVisitor for PlaceholderExpander {
349349
fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
350350
match expr.kind {
351351
ast::ExprKind::MacCall(_) => self.remove(expr.id).make_opt_expr(),
352-
_ => noop_filter_map_expr(self, expr),
352+
_ => walk_filter_map_expr(self, expr),
353353
}
354354
}
355355

0 commit comments

Comments
 (0)