From 754bdef79345db368c7af43df3fae1c5cbed6c91 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 10 Jul 2024 08:17:13 +0000 Subject: [PATCH] Sync `mut_visit` function names with immut `visit` ones (s/noop_visit/walk/) --- compiler/rustc_ast/src/mut_visit.rs | 259 +++++++++--------- compiler/rustc_builtin_macros/src/cfg_eval.rs | 28 +- .../rustc_builtin_macros/src/test_harness.rs | 6 +- compiler/rustc_expand/src/expand.rs | 108 ++++---- compiler/rustc_expand/src/placeholders.rs | 32 +-- compiler/rustc_parse/src/parser/expr.rs | 12 +- compiler/rustc_parse/src/parser/pat.rs | 4 +- .../clippy_lints/src/unnested_or_patterns.rs | 8 +- tests/ui-fulldeps/pprust-expr-roundtrip.rs | 4 +- 9 files changed, 226 insertions(+), 235 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 2d749bd8fd4..56dd6663bb6 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -36,7 +36,7 @@ impl ExpectOne for SmallVec { } pub trait NoopVisitItemKind { - fn noop_visit( + fn walk( &mut self, ctxt: Option, ident: Ident, @@ -86,35 +86,35 @@ pub trait MutVisitor: Sized { // forget to add handling for it. fn visit_crate(&mut self, c: &mut Crate) { - noop_visit_crate(c, self) + walk_crate(c, self) } fn visit_meta_list_item(&mut self, list_item: &mut NestedMetaItem) { - noop_visit_meta_list_item(list_item, self); + walk_meta_list_item(list_item, self); } fn visit_meta_item(&mut self, meta_item: &mut MetaItem) { - noop_visit_meta_item(meta_item, self); + walk_meta_item(meta_item, self); } fn visit_use_tree(&mut self, use_tree: &mut UseTree) { - noop_visit_use_tree(use_tree, self); + walk_use_tree(use_tree, self); } fn flat_map_foreign_item(&mut self, ni: P) -> SmallVec<[P; 1]> { - noop_flat_map_item(ni, None, self) + walk_flat_map_item(ni, None, self) } fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { - noop_flat_map_item(i, None, self) + walk_flat_map_item(i, None, self) } fn visit_fn_header(&mut self, header: &mut FnHeader) { - noop_visit_fn_header(header, self); + walk_fn_header(header, self); } fn flat_map_field_def(&mut self, fd: FieldDef) -> SmallVec<[FieldDef; 1]> { - noop_flat_map_field_def(fd, self) + walk_flat_map_field_def(fd, self) } fn flat_map_assoc_item( @@ -122,48 +122,48 @@ pub trait MutVisitor: Sized { i: P, ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { - noop_flat_map_item(i, Some(ctxt), self) + walk_flat_map_item(i, Some(ctxt), self) } fn visit_fn_decl(&mut self, d: &mut P) { - noop_visit_fn_decl(d, self); + walk_fn_decl(d, self); } /// `Span` and `NodeId` are mutated at the caller site. fn visit_fn(&mut self, fk: FnKind<'_>, _: Span, _: NodeId) { - noop_visit_fn(fk, self) + walk_fn(fk, self) } fn visit_coroutine_kind(&mut self, a: &mut CoroutineKind) { - noop_visit_coroutine_kind(a, self); + walk_coroutine_kind(a, self); } fn visit_closure_binder(&mut self, b: &mut ClosureBinder) { - noop_visit_closure_binder(b, self); + walk_closure_binder(b, self); } fn visit_block(&mut self, b: &mut P) { - noop_visit_block(b, self); + walk_block(b, self); } fn flat_map_stmt(&mut self, s: Stmt) -> SmallVec<[Stmt; 1]> { - noop_flat_map_stmt(s, self) + walk_flat_map_stmt(s, self) } fn flat_map_arm(&mut self, arm: Arm) -> SmallVec<[Arm; 1]> { - noop_flat_map_arm(arm, self) + walk_flat_map_arm(arm, self) } fn visit_pat(&mut self, p: &mut P) { - noop_visit_pat(p, self); + walk_pat(p, self); } fn visit_anon_const(&mut self, c: &mut AnonConst) { - noop_visit_anon_const(c, self); + walk_anon_const(c, self); } fn visit_expr(&mut self, e: &mut P) { - noop_visit_expr(e, self); + walk_expr(e, self); } /// This method is a hack to workaround unstable of `stmt_expr_attributes`. @@ -177,127 +177,127 @@ pub trait MutVisitor: Sized { } fn visit_generic_arg(&mut self, arg: &mut GenericArg) { - noop_visit_generic_arg(arg, self); + walk_generic_arg(arg, self); } fn visit_ty(&mut self, t: &mut P) { - noop_visit_ty(t, self); + walk_ty(t, self); } fn visit_lifetime(&mut self, l: &mut Lifetime) { - noop_visit_lifetime(l, self); + walk_lifetime(l, self); } fn visit_assoc_item_constraint(&mut self, c: &mut AssocItemConstraint) { - noop_visit_assoc_item_constraint(c, self); + walk_assoc_item_constraint(c, self); } fn visit_foreign_mod(&mut self, nm: &mut ForeignMod) { - noop_visit_foreign_mod(nm, self); + walk_foreign_mod(nm, self); } fn flat_map_variant(&mut self, v: Variant) -> SmallVec<[Variant; 1]> { - noop_flat_map_variant(v, self) + walk_flat_map_variant(v, self) } fn visit_ident(&mut self, i: &mut Ident) { - noop_visit_ident(i, self); + walk_ident(i, self); } fn visit_path(&mut self, p: &mut Path) { - noop_visit_path(p, self); + walk_path(self, p); } fn visit_path_segment(&mut self, p: &mut PathSegment) { - noop_visit_path_segment(p, self) + walk_path_segment(self, p) } fn visit_qself(&mut self, qs: &mut Option>) { - noop_visit_qself(qs, self); + walk_qself(qs, self); } fn visit_generic_args(&mut self, p: &mut GenericArgs) { - noop_visit_generic_args(p, self); + walk_generic_args(p, self); } fn visit_angle_bracketed_parameter_data(&mut self, p: &mut AngleBracketedArgs) { - noop_visit_angle_bracketed_parameter_data(p, self); + walk_angle_bracketed_parameter_data(p, self); } fn visit_parenthesized_parameter_data(&mut self, p: &mut ParenthesizedArgs) { - noop_visit_parenthesized_parameter_data(p, self); + walk_parenthesized_parameter_data(p, self); } fn visit_local(&mut self, l: &mut P) { - noop_visit_local(l, self); + walk_local(l, self); } fn visit_mac_call(&mut self, mac: &mut MacCall) { - noop_visit_mac(mac, self); + walk_mac(mac, self); } fn visit_macro_def(&mut self, def: &mut MacroDef) { - noop_visit_macro_def(def, self); + walk_macro_def(def, self); } fn visit_label(&mut self, label: &mut Label) { - noop_visit_label(label, self); + walk_label(label, self); } fn visit_attribute(&mut self, at: &mut Attribute) { - noop_visit_attribute(at, self); + walk_attribute(at, self); } fn flat_map_param(&mut self, param: Param) -> SmallVec<[Param; 1]> { - noop_flat_map_param(param, self) + walk_flat_map_param(param, self) } fn visit_generics(&mut self, generics: &mut Generics) { - noop_visit_generics(generics, self); + walk_generics(generics, self); } fn visit_trait_ref(&mut self, tr: &mut TraitRef) { - noop_visit_trait_ref(tr, self); + walk_trait_ref(tr, self); } fn visit_poly_trait_ref(&mut self, p: &mut PolyTraitRef) { - noop_visit_poly_trait_ref(p, self); + walk_poly_trait_ref(p, self); } fn visit_variant_data(&mut self, vdata: &mut VariantData) { - noop_visit_variant_data(vdata, self); + walk_variant_data(vdata, self); } fn flat_map_generic_param(&mut self, param: GenericParam) -> SmallVec<[GenericParam; 1]> { - noop_flat_map_generic_param(param, self) + walk_flat_map_generic_param(param, self) } fn visit_param_bound(&mut self, tpb: &mut GenericBound, _ctxt: BoundKind) { - noop_visit_param_bound(tpb, self); + walk_param_bound(tpb, self); } fn visit_precise_capturing_arg(&mut self, arg: &mut PreciseCapturingArg) { - noop_visit_precise_capturing_arg(arg, self); + walk_precise_capturing_arg(arg, self); } fn visit_mt(&mut self, mt: &mut MutTy) { - noop_visit_mt(mt, self); + walk_mt(mt, self); } fn flat_map_expr_field(&mut self, f: ExprField) -> SmallVec<[ExprField; 1]> { - noop_flat_map_expr_field(f, self) + walk_flat_map_expr_field(f, self) } fn visit_where_clause(&mut self, where_clause: &mut WhereClause) { - noop_visit_where_clause(where_clause, self); + walk_where_clause(where_clause, self); } fn visit_where_predicate(&mut self, where_predicate: &mut WherePredicate) { - noop_visit_where_predicate(where_predicate, self); + walk_where_predicate(where_predicate, self); } fn visit_vis(&mut self, vis: &mut Visibility) { - noop_visit_vis(vis, self); + walk_vis(vis, self); } fn visit_id(&mut self, _id: &mut NodeId) { @@ -309,23 +309,23 @@ pub trait MutVisitor: Sized { } fn flat_map_pat_field(&mut self, fp: PatField) -> SmallVec<[PatField; 1]> { - noop_flat_map_pat_field(fp, self) + walk_flat_map_pat_field(fp, self) } fn visit_inline_asm(&mut self, asm: &mut InlineAsm) { - noop_visit_inline_asm(asm, self) + walk_inline_asm(asm, self) } fn visit_inline_asm_sym(&mut self, sym: &mut InlineAsmSym) { - noop_visit_inline_asm_sym(sym, self) + walk_inline_asm_sym(sym, self) } fn visit_format_args(&mut self, fmt: &mut FormatArgs) { - noop_visit_format_args(fmt, self) + walk_format_args(fmt, self) } fn visit_capture_by(&mut self, capture_by: &mut CaptureBy) { - noop_visit_capture_by(capture_by, self) + walk_capture_by(capture_by, self) } } @@ -422,7 +422,7 @@ pub fn visit_delim_span(DelimSpan { open, close }: &mut DelimSpan vis.visit_span(close); } -pub fn noop_flat_map_pat_field( +pub fn walk_flat_map_pat_field( mut fp: PatField, vis: &mut T, ) -> SmallVec<[PatField; 1]> { @@ -435,7 +435,7 @@ pub fn noop_flat_map_pat_field( smallvec![fp] } -fn noop_visit_use_tree(use_tree: &mut UseTree, vis: &mut T) { +fn walk_use_tree(use_tree: &mut UseTree, vis: &mut T) { let UseTree { prefix, kind, span } = use_tree; vis.visit_path(prefix); match kind { @@ -452,7 +452,7 @@ fn noop_visit_use_tree(use_tree: &mut UseTree, vis: &mut T) { vis.visit_span(span); } -pub fn noop_flat_map_arm(mut arm: Arm, vis: &mut T) -> SmallVec<[Arm; 1]> { +pub fn walk_flat_map_arm(mut arm: Arm, vis: &mut T) -> SmallVec<[Arm; 1]> { let Arm { attrs, pat, guard, body, span, id, is_placeholder: _ } = &mut arm; vis.visit_id(id); visit_attrs(attrs, vis); @@ -463,7 +463,7 @@ pub fn noop_flat_map_arm(mut arm: Arm, vis: &mut T) -> SmallVec<[ smallvec![arm] } -fn noop_visit_assoc_item_constraint( +fn walk_assoc_item_constraint( AssocItemConstraint { id, ident, gen_args, kind, span }: &mut AssocItemConstraint, vis: &mut T, ) { @@ -482,7 +482,7 @@ fn noop_visit_assoc_item_constraint( vis.visit_span(span); } -pub fn noop_visit_ty(ty: &mut P, vis: &mut T) { +pub fn walk_ty(ty: &mut P, vis: &mut T) { let Ty { id, kind, span, tokens } = ty.deref_mut(); vis.visit_id(id); match kind { @@ -534,13 +534,13 @@ pub fn noop_visit_ty(ty: &mut P, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_foreign_mod(foreign_mod: &mut ForeignMod, vis: &mut T) { +fn walk_foreign_mod(foreign_mod: &mut ForeignMod, vis: &mut T) { let ForeignMod { safety, abi: _, items } = foreign_mod; visit_safety(safety, vis); items.flat_map_in_place(|item| vis.flat_map_foreign_item(item)); } -pub fn noop_flat_map_variant( +pub fn walk_flat_map_variant( mut variant: Variant, visitor: &mut T, ) -> SmallVec<[Variant; 1]> { @@ -555,18 +555,18 @@ pub fn noop_flat_map_variant( smallvec![variant] } -fn noop_visit_ident(Ident { name: _, span }: &mut Ident, vis: &mut T) { +fn walk_ident(Ident { name: _, span }: &mut Ident, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_path_segment(segment: &mut PathSegment, vis: &mut T) { +fn walk_path_segment(vis: &mut T, segment: &mut PathSegment) { let PathSegment { ident, id, args } = segment; vis.visit_id(id); vis.visit_ident(ident); visit_opt(args, |args| vis.visit_generic_args(args)); } -fn noop_visit_path(Path { segments, span, tokens }: &mut Path, vis: &mut T) { +fn walk_path(vis: &mut T, Path { segments, span, tokens }: &mut Path) { for segment in segments { vis.visit_path_segment(segment); } @@ -574,7 +574,7 @@ fn noop_visit_path(Path { segments, span, tokens }: &mut Path, vi vis.visit_span(span); } -fn noop_visit_qself(qself: &mut Option>, vis: &mut T) { +fn walk_qself(qself: &mut Option>, vis: &mut T) { visit_opt(qself, |qself| { let QSelf { ty, path_span, position: _ } = &mut **qself; vis.visit_ty(ty); @@ -582,7 +582,7 @@ fn noop_visit_qself(qself: &mut Option>, vis: &mut T) { }) } -fn noop_visit_generic_args(generic_args: &mut GenericArgs, vis: &mut T) { +fn walk_generic_args(generic_args: &mut GenericArgs, vis: &mut T) { match generic_args { GenericArgs::AngleBracketed(data) => vis.visit_angle_bracketed_parameter_data(data), GenericArgs::Parenthesized(data) => vis.visit_parenthesized_parameter_data(data), @@ -590,7 +590,7 @@ fn noop_visit_generic_args(generic_args: &mut GenericArgs, vis: & } } -fn noop_visit_generic_arg(arg: &mut GenericArg, vis: &mut T) { +fn walk_generic_arg(arg: &mut GenericArg, vis: &mut T) { match arg { GenericArg::Lifetime(lt) => vis.visit_lifetime(lt), GenericArg::Type(ty) => vis.visit_ty(ty), @@ -598,10 +598,7 @@ fn noop_visit_generic_arg(arg: &mut GenericArg, vis: &mut T) { } } -fn noop_visit_angle_bracketed_parameter_data( - data: &mut AngleBracketedArgs, - vis: &mut T, -) { +fn walk_angle_bracketed_parameter_data(data: &mut AngleBracketedArgs, vis: &mut T) { let AngleBracketedArgs { args, span } = data; visit_thin_vec(args, |arg| match arg { AngleBracketedArg::Arg(arg) => vis.visit_generic_arg(arg), @@ -610,18 +607,15 @@ fn noop_visit_angle_bracketed_parameter_data( vis.visit_span(span); } -fn noop_visit_parenthesized_parameter_data( - args: &mut ParenthesizedArgs, - vis: &mut T, -) { +fn walk_parenthesized_parameter_data(args: &mut ParenthesizedArgs, vis: &mut T) { let ParenthesizedArgs { inputs, output, span, inputs_span } = args; visit_thin_vec(inputs, |input| vis.visit_ty(input)); - noop_visit_fn_ret_ty(output, vis); + walk_fn_ret_ty(output, vis); vis.visit_span(span); vis.visit_span(inputs_span); } -fn noop_visit_local(local: &mut P, vis: &mut T) { +fn walk_local(local: &mut P, vis: &mut T) { let Local { id, pat, ty, kind, span, colon_sp, attrs, tokens } = local.deref_mut(); vis.visit_id(id); visit_attrs(attrs, vis); @@ -642,7 +636,7 @@ fn noop_visit_local(local: &mut P, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_attribute(attr: &mut Attribute, vis: &mut T) { +fn walk_attribute(attr: &mut Attribute, vis: &mut T) { let Attribute { kind, id: _, style: _, span } = attr; match kind { AttrKind::Normal(normal) => { @@ -660,25 +654,25 @@ fn noop_visit_attribute(attr: &mut Attribute, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_mac(mac: &mut MacCall, vis: &mut T) { +fn walk_mac(mac: &mut MacCall, vis: &mut T) { let MacCall { path, args } = mac; vis.visit_path(path); visit_delim_args(args, vis); } -fn noop_visit_macro_def(macro_def: &mut MacroDef, vis: &mut T) { +fn walk_macro_def(macro_def: &mut MacroDef, vis: &mut T) { let MacroDef { body, macro_rules: _ } = macro_def; visit_delim_args(body, vis); } -fn noop_visit_meta_list_item(li: &mut NestedMetaItem, vis: &mut T) { +fn walk_meta_list_item(li: &mut NestedMetaItem, vis: &mut T) { match li { NestedMetaItem::MetaItem(mi) => vis.visit_meta_item(mi), NestedMetaItem::Lit(_lit) => {} } } -fn noop_visit_meta_item(mi: &mut MetaItem, vis: &mut T) { +fn walk_meta_item(mi: &mut MetaItem, vis: &mut T) { let MetaItem { unsafety: _, path: _, kind, span } = mi; match kind { MetaItemKind::Word => {} @@ -688,7 +682,7 @@ fn noop_visit_meta_item(mi: &mut MetaItem, vis: &mut T) { vis.visit_span(span); } -pub fn noop_flat_map_param(mut param: Param, vis: &mut T) -> SmallVec<[Param; 1]> { +pub fn walk_flat_map_param(mut param: Param, vis: &mut T) -> SmallVec<[Param; 1]> { let Param { attrs, id, pat, span, ty, is_placeholder: _ } = &mut param; vis.visit_id(id); visit_attrs(attrs, vis); @@ -873,7 +867,7 @@ fn visit_constness(constness: &mut Const, vis: &mut T) { } } -fn noop_visit_closure_binder(binder: &mut ClosureBinder, vis: &mut T) { +fn walk_closure_binder(binder: &mut ClosureBinder, vis: &mut T) { match binder { ClosureBinder::NotPresent => {} ClosureBinder::For { span: _, generic_params } => { @@ -882,7 +876,7 @@ fn noop_visit_closure_binder(binder: &mut ClosureBinder, vis: &mu } } -fn noop_visit_coroutine_kind(coroutine_kind: &mut CoroutineKind, vis: &mut T) { +fn walk_coroutine_kind(coroutine_kind: &mut CoroutineKind, vis: &mut T) { match coroutine_kind { CoroutineKind::Async { span, closure_id, return_impl_trait_id } | CoroutineKind::Gen { span, closure_id, return_impl_trait_id } @@ -894,7 +888,7 @@ fn noop_visit_coroutine_kind(coroutine_kind: &mut CoroutineKind, } } -fn noop_visit_fn(kind: FnKind<'_>, vis: &mut T) { +fn walk_fn(kind: FnKind<'_>, vis: &mut T) { match kind { FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span }, generics, body) => { // Identifier and visibility are visited as a part of the item. @@ -914,23 +908,23 @@ fn noop_visit_fn(kind: FnKind<'_>, vis: &mut T) { } } -fn noop_visit_fn_decl(decl: &mut P, vis: &mut T) { +fn walk_fn_decl(decl: &mut P, vis: &mut T) { let FnDecl { inputs, output } = decl.deref_mut(); inputs.flat_map_in_place(|param| vis.flat_map_param(param)); - noop_visit_fn_ret_ty(output, vis); + walk_fn_ret_ty(output, vis); } -fn noop_visit_fn_ret_ty(fn_ret_ty: &mut FnRetTy, vis: &mut T) { +fn walk_fn_ret_ty(fn_ret_ty: &mut FnRetTy, vis: &mut T) { match fn_ret_ty { FnRetTy::Default(span) => vis.visit_span(span), FnRetTy::Ty(ty) => vis.visit_ty(ty), } } -fn noop_visit_param_bound(pb: &mut GenericBound, vis: &mut T) { +fn walk_param_bound(pb: &mut GenericBound, vis: &mut T) { match pb { GenericBound::Trait(ty, _modifier) => vis.visit_poly_trait_ref(ty), - GenericBound::Outlives(lifetime) => noop_visit_lifetime(lifetime, vis), + GenericBound::Outlives(lifetime) => walk_lifetime(lifetime, vis), GenericBound::Use(args, span) => { for arg in args { vis.visit_precise_capturing_arg(arg); @@ -940,7 +934,7 @@ fn noop_visit_param_bound(pb: &mut GenericBound, vis: &mut T) { } } -fn noop_visit_precise_capturing_arg(arg: &mut PreciseCapturingArg, vis: &mut T) { +fn walk_precise_capturing_arg(arg: &mut PreciseCapturingArg, vis: &mut T) { match arg { PreciseCapturingArg::Lifetime(lt) => { vis.visit_lifetime(lt); @@ -952,7 +946,7 @@ fn noop_visit_precise_capturing_arg(arg: &mut PreciseCapturingArg } } -pub fn noop_flat_map_generic_param( +pub fn walk_flat_map_generic_param( mut param: GenericParam, vis: &mut T, ) -> SmallVec<[GenericParam; 1]> { @@ -977,23 +971,23 @@ pub fn noop_flat_map_generic_param( smallvec![param] } -fn noop_visit_label(Label { ident }: &mut Label, vis: &mut T) { +fn walk_label(Label { ident }: &mut Label, vis: &mut T) { vis.visit_ident(ident); } -fn noop_visit_lifetime(Lifetime { id, ident }: &mut Lifetime, vis: &mut T) { +fn walk_lifetime(Lifetime { id, ident }: &mut Lifetime, vis: &mut T) { vis.visit_id(id); vis.visit_ident(ident); } -fn noop_visit_generics(generics: &mut Generics, vis: &mut T) { +fn walk_generics(generics: &mut Generics, vis: &mut T) { let Generics { params, where_clause, span } = generics; params.flat_map_in_place(|param| vis.flat_map_generic_param(param)); vis.visit_where_clause(where_clause); vis.visit_span(span); } -fn noop_visit_ty_alias_where_clauses(tawcs: &mut TyAliasWhereClauses, vis: &mut T) { +fn walk_ty_alias_where_clauses(tawcs: &mut TyAliasWhereClauses, vis: &mut T) { let TyAliasWhereClauses { before, after, split: _ } = tawcs; let TyAliasWhereClause { has_where_token: _, span: span_before } = before; let TyAliasWhereClause { has_where_token: _, span: span_after } = after; @@ -1001,13 +995,13 @@ fn noop_visit_ty_alias_where_clauses(tawcs: &mut TyAliasWhereClau vis.visit_span(span_after); } -fn noop_visit_where_clause(wc: &mut WhereClause, vis: &mut T) { +fn walk_where_clause(wc: &mut WhereClause, vis: &mut T) { let WhereClause { has_where_token: _, predicates, span } = wc; visit_thin_vec(predicates, |predicate| vis.visit_where_predicate(predicate)); vis.visit_span(span); } -fn noop_visit_where_predicate(pred: &mut WherePredicate, vis: &mut T) { +fn walk_where_predicate(pred: &mut WherePredicate, vis: &mut T) { match pred { WherePredicate::BoundPredicate(bp) => { let WhereBoundPredicate { span, bound_generic_params, bounded_ty, bounds } = bp; @@ -1031,7 +1025,7 @@ fn noop_visit_where_predicate(pred: &mut WherePredicate, vis: &mu } } -fn noop_visit_variant_data(vdata: &mut VariantData, vis: &mut T) { +fn walk_variant_data(vdata: &mut VariantData, vis: &mut T) { match vdata { VariantData::Struct { fields, recovered: _ } => { fields.flat_map_in_place(|field| vis.flat_map_field_def(field)); @@ -1044,19 +1038,19 @@ fn noop_visit_variant_data(vdata: &mut VariantData, vis: &mut T) } } -fn noop_visit_trait_ref(TraitRef { path, ref_id }: &mut TraitRef, vis: &mut T) { +fn walk_trait_ref(TraitRef { path, ref_id }: &mut TraitRef, vis: &mut T) { vis.visit_id(ref_id); vis.visit_path(path); } -fn noop_visit_poly_trait_ref(p: &mut PolyTraitRef, vis: &mut T) { +fn walk_poly_trait_ref(p: &mut PolyTraitRef, vis: &mut T) { let PolyTraitRef { bound_generic_params, trait_ref, span } = p; bound_generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param)); vis.visit_trait_ref(trait_ref); vis.visit_span(span); } -pub fn noop_flat_map_field_def( +pub fn walk_flat_map_field_def( mut fd: FieldDef, visitor: &mut T, ) -> SmallVec<[FieldDef; 1]> { @@ -1070,7 +1064,7 @@ pub fn noop_flat_map_field_def( smallvec![fd] } -pub fn noop_flat_map_expr_field( +pub fn walk_flat_map_expr_field( mut f: ExprField, vis: &mut T, ) -> SmallVec<[ExprField; 1]> { @@ -1083,11 +1077,11 @@ pub fn noop_flat_map_expr_field( smallvec![f] } -fn noop_visit_mt(MutTy { ty, mutbl: _ }: &mut MutTy, vis: &mut T) { +fn walk_mt(MutTy { ty, mutbl: _ }: &mut MutTy, vis: &mut T) { vis.visit_ty(ty); } -pub fn noop_visit_block(block: &mut P, vis: &mut T) { +pub fn walk_block(block: &mut P, vis: &mut T) { let Block { id, stmts, rules: _, span, tokens, could_be_bare_literal: _ } = block.deref_mut(); vis.visit_id(id); stmts.flat_map_in_place(|stmt| vis.flat_map_stmt(stmt)); @@ -1095,18 +1089,18 @@ pub fn noop_visit_block(block: &mut P, vis: &mut T) { vis.visit_span(span); } -pub fn noop_visit_item_kind( +pub fn walk_item_kind( kind: &mut impl NoopVisitItemKind, ident: Ident, span: Span, id: NodeId, vis: &mut impl MutVisitor, ) { - kind.noop_visit(None, ident, span, id, vis) + kind.walk(None, ident, span, id, vis) } impl NoopVisitItemKind for ItemKind { - fn noop_visit( + fn walk( &mut self, ctxt: Option, ident: Ident, @@ -1147,7 +1141,7 @@ impl NoopVisitItemKind for ItemKind { vis.visit_generics(generics); visit_bounds(bounds, BoundKind::Bound, vis); visit_opt(ty, |ty| vis.visit_ty(ty)); - noop_visit_ty_alias_where_clauses(where_clauses, vis); + walk_ty_alias_where_clauses(where_clauses, vis); } ItemKind::Enum(EnumDef { variants }, generics) => { vis.visit_generics(generics); @@ -1226,7 +1220,7 @@ impl NoopVisitItemKind for ItemKind { } impl NoopVisitItemKind for AssocItemKind { - fn noop_visit( + fn walk( &mut self, ctxt: Option, ident: Ident, @@ -1258,7 +1252,7 @@ impl NoopVisitItemKind for AssocItemKind { visitor.visit_generics(generics); visit_bounds(bounds, BoundKind::Bound, visitor); visit_opt(ty, |ty| visitor.visit_ty(ty)); - noop_visit_ty_alias_where_clauses(where_clauses, visitor); + walk_ty_alias_where_clauses(where_clauses, visitor); } AssocItemKind::MacCall(mac) => visitor.visit_mac_call(mac), AssocItemKind::Delegation(box Delegation { @@ -1308,14 +1302,14 @@ fn visit_const_item( visit_opt(expr, |expr| visitor.visit_expr(expr)); } -fn noop_visit_fn_header(header: &mut FnHeader, vis: &mut T) { +fn walk_fn_header(header: &mut FnHeader, vis: &mut T) { let FnHeader { safety, coroutine_kind, constness, ext: _ } = header; visit_constness(constness, vis); coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind)); visit_safety(safety, vis); } -pub fn noop_visit_crate(krate: &mut Crate, vis: &mut T) { +pub fn walk_crate(krate: &mut Crate, vis: &mut T) { let Crate { attrs, items, spans, id, is_placeholder: _ } = krate; vis.visit_id(id); visit_attrs(attrs, vis); @@ -1326,7 +1320,7 @@ pub fn noop_visit_crate(krate: &mut Crate, vis: &mut T) { } /// Mutates one item, returning the item again. -pub fn noop_flat_map_item( +pub fn walk_flat_map_item( mut item: P>, ctxt: Option, visitor: &mut impl MutVisitor, @@ -1336,14 +1330,14 @@ pub fn noop_flat_map_item( visit_attrs(attrs, visitor); visitor.visit_vis(vis); visitor.visit_ident(ident); - kind.noop_visit(ctxt, *ident, *span, *id, visitor); + kind.walk(ctxt, *ident, *span, *id, visitor); visit_lazy_tts(tokens, visitor); visitor.visit_span(span); smallvec![item] } impl NoopVisitItemKind for ForeignItemKind { - fn noop_visit( + fn walk( &mut self, ctxt: Option, ident: Ident, @@ -1372,14 +1366,14 @@ impl NoopVisitItemKind for ForeignItemKind { visitor.visit_generics(generics); visit_bounds(bounds, BoundKind::Bound, visitor); visit_opt(ty, |ty| visitor.visit_ty(ty)); - noop_visit_ty_alias_where_clauses(where_clauses, visitor); + walk_ty_alias_where_clauses(where_clauses, visitor); } ForeignItemKind::MacCall(mac) => visitor.visit_mac_call(mac), } } } -pub fn noop_visit_pat(pat: &mut P, vis: &mut T) { +pub fn walk_pat(pat: &mut P, vis: &mut T) { let Pat { id, kind, span, tokens } = pat.deref_mut(); vis.visit_id(id); match kind { @@ -1422,12 +1416,12 @@ pub fn noop_visit_pat(pat: &mut P, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_anon_const(AnonConst { id, value }: &mut AnonConst, vis: &mut T) { +fn walk_anon_const(AnonConst { id, value }: &mut AnonConst, vis: &mut T) { vis.visit_id(id); vis.visit_expr(value); } -fn noop_visit_inline_asm(asm: &mut InlineAsm, vis: &mut T) { +fn walk_inline_asm(asm: &mut InlineAsm, vis: &mut T) { // FIXME: Visit spans inside all this currently ignored stuff. let InlineAsm { template: _, @@ -1457,7 +1451,7 @@ fn noop_visit_inline_asm(asm: &mut InlineAsm, vis: &mut T) { } } -fn noop_visit_inline_asm_sym( +fn walk_inline_asm_sym( InlineAsmSym { id, qself, path }: &mut InlineAsmSym, vis: &mut T, ) { @@ -1466,7 +1460,7 @@ fn noop_visit_inline_asm_sym( vis.visit_path(path); } -fn noop_visit_format_args(fmt: &mut FormatArgs, vis: &mut T) { +fn walk_format_args(fmt: &mut FormatArgs, vis: &mut T) { // FIXME: visit the template exhaustively. let FormatArgs { span, template: _, arguments } = fmt; for FormatArgument { kind, expr } in arguments.all_args_mut() { @@ -1481,10 +1475,7 @@ fn noop_visit_format_args(fmt: &mut FormatArgs, vis: &mut T) { vis.visit_span(span); } -pub fn noop_visit_expr( - Expr { kind, id, span, attrs, tokens }: &mut Expr, - vis: &mut T, -) { +pub fn walk_expr(Expr { kind, id, span, attrs, tokens }: &mut Expr, vis: &mut T) { vis.visit_id(id); visit_attrs(attrs, vis); match kind { @@ -1673,12 +1664,12 @@ pub fn noop_filter_map_expr(mut e: P, vis: &mut T) -> Optio }) } -pub fn noop_flat_map_stmt( +pub fn walk_flat_map_stmt( Stmt { kind, mut span, mut id }: Stmt, vis: &mut T, ) -> SmallVec<[Stmt; 1]> { vis.visit_id(&mut id); - let stmts: SmallVec<_> = noop_flat_map_stmt_kind(kind, vis) + let stmts: SmallVec<_> = walk_flat_map_stmt_kind(kind, vis) .into_iter() .map(|kind| Stmt { id, kind, span }) .collect(); @@ -1692,7 +1683,7 @@ pub fn noop_flat_map_stmt( stmts } -fn noop_flat_map_stmt_kind(kind: StmtKind, vis: &mut T) -> SmallVec<[StmtKind; 1]> { +fn walk_flat_map_stmt_kind(kind: StmtKind, vis: &mut T) -> SmallVec<[StmtKind; 1]> { match kind { StmtKind::Let(mut local) => smallvec![StmtKind::Let({ vis.visit_local(&mut local); @@ -1712,7 +1703,7 @@ fn noop_flat_map_stmt_kind(kind: StmtKind, vis: &mut T) -> SmallV } } -fn noop_visit_vis(visibility: &mut Visibility, vis: &mut T) { +fn walk_vis(visibility: &mut Visibility, vis: &mut T) { let Visibility { kind, span, tokens } = visibility; match kind { VisibilityKind::Public | VisibilityKind::Inherited => {} @@ -1725,7 +1716,7 @@ fn noop_visit_vis(visibility: &mut Visibility, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_capture_by(capture_by: &mut CaptureBy, vis: &mut T) { +fn walk_capture_by(capture_by: &mut CaptureBy, vis: &mut T) { match capture_by { CaptureBy::Ref => {} CaptureBy::Value { move_kw } => { diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs index 1cfbaf9d669..39d66b5a6de 100644 --- a/compiler/rustc_builtin_macros/src/cfg_eval.rs +++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs @@ -212,18 +212,18 @@ impl MutVisitor for CfgEval<'_> { #[instrument(level = "trace", skip(self))] fn visit_expr(&mut self, expr: &mut P) { self.0.configure_expr(expr, false); - mut_visit::noop_visit_expr(expr, self); + mut_visit::walk_expr(expr, self); } #[instrument(level = "trace", skip(self))] fn visit_method_receiver_expr(&mut self, expr: &mut P) { self.0.configure_expr(expr, true); - mut_visit::noop_visit_expr(expr, self); + mut_visit::walk_expr(expr, self); } fn filter_map_expr(&mut self, expr: P) -> Option> { let mut expr = configure!(self, expr); - mut_visit::noop_visit_expr(&mut expr, self); + mut_visit::walk_expr(&mut expr, self); Some(expr) } @@ -231,15 +231,15 @@ impl MutVisitor for CfgEval<'_> { &mut self, param: ast::GenericParam, ) -> SmallVec<[ast::GenericParam; 1]> { - mut_visit::noop_flat_map_generic_param(configure!(self, param), self) + mut_visit::walk_flat_map_generic_param(configure!(self, param), self) } fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { - mut_visit::noop_flat_map_stmt(configure!(self, stmt), self) + mut_visit::walk_flat_map_stmt(configure!(self, stmt), self) } fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { - mut_visit::noop_flat_map_item(configure!(self, item), None, self) + mut_visit::walk_flat_map_item(configure!(self, item), None, self) } fn flat_map_assoc_item( @@ -247,37 +247,37 @@ impl MutVisitor for CfgEval<'_> { item: P, ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { - mut_visit::noop_flat_map_item(configure!(self, item), Some(ctxt), self) + mut_visit::walk_flat_map_item(configure!(self, item), Some(ctxt), self) } fn flat_map_foreign_item( &mut self, foreign_item: P, ) -> SmallVec<[P; 1]> { - mut_visit::noop_flat_map_item(configure!(self, foreign_item), None, self) + mut_visit::walk_flat_map_item(configure!(self, foreign_item), None, self) } fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> { - mut_visit::noop_flat_map_arm(configure!(self, arm), self) + mut_visit::walk_flat_map_arm(configure!(self, arm), self) } fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> { - mut_visit::noop_flat_map_expr_field(configure!(self, field), self) + mut_visit::walk_flat_map_expr_field(configure!(self, field), self) } fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> { - mut_visit::noop_flat_map_pat_field(configure!(self, fp), self) + mut_visit::walk_flat_map_pat_field(configure!(self, fp), self) } fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> { - mut_visit::noop_flat_map_param(configure!(self, p), self) + mut_visit::walk_flat_map_param(configure!(self, p), self) } fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> { - mut_visit::noop_flat_map_field_def(configure!(self, sf), self) + mut_visit::walk_flat_map_field_def(configure!(self, sf), self) } fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> { - mut_visit::noop_flat_map_variant(configure!(self, variant), self) + mut_visit::walk_flat_map_variant(configure!(self, variant), self) } } diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 88712ad569b..2e4d60a0817 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -122,7 +122,7 @@ impl TestHarnessGenerator<'_> { impl<'a> MutVisitor for TestHarnessGenerator<'a> { fn visit_crate(&mut self, c: &mut ast::Crate) { let prev_tests = mem::take(&mut self.tests); - noop_visit_crate(c, self); + walk_crate(c, self); self.add_test_cases(ast::CRATE_NODE_ID, c.spans.inner_span, prev_tests); // Create a main function to run our tests @@ -144,7 +144,7 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> { item.kind { let prev_tests = mem::take(&mut self.tests); - noop_visit_item_kind(&mut item.kind, item.ident, item.span, item.id, self); + walk_item_kind(&mut item.kind, item.ident, item.span, item.id, self); self.add_test_cases(item.id, span, prev_tests); } else { // But in those cases, we emit a lint to warn the user of these missing tests. @@ -192,7 +192,7 @@ struct EntryPointCleaner<'a> { impl<'a> MutVisitor for EntryPointCleaner<'a> { fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { self.depth += 1; - let item = noop_flat_map_item(i, None, self).expect_one("noop did something"); + let item = walk_flat_map_item(i, None, self).expect_one("noop did something"); self.depth -= 1; // Remove any #[rustc_main] or #[start] from the AST so it doesn't diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 6f4df7bb168..c10b7114123 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1036,7 +1036,7 @@ pub(crate) fn ensure_complete_parse<'a>( } } -/// Wraps a call to `noop_visit_*` / `noop_flat_map_*` +/// Wraps a call to `walk_*` / `walk_flat_map_*` /// for an AST node that supports attributes /// (see the `Annotatable` enum) /// This method assigns a `NodeId`, and sets that `NodeId` @@ -1056,7 +1056,7 @@ pub(crate) fn ensure_complete_parse<'a>( /// * `id` is a mutable reference to the `NodeId` field /// of the current AST node. /// * `closure` is a closure that executes the -/// `noop_visit_*` / `noop_flat_map_*` method +/// `walk_*` / `walk_flat_map_*` method /// for the current AST node. macro_rules! assign_id { ($self:ident, $id:expr, $closure:expr) => {{ @@ -1090,10 +1090,10 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized { fn descr() -> &'static str { unreachable!() } - fn noop_flat_map(self, _visitor: &mut V) -> Self::OutputTy { + fn walk_flat_map(self, _visitor: &mut V) -> Self::OutputTy { unreachable!() } - fn noop_visit(&mut self, _visitor: &mut V) { + fn walk(&mut self, _visitor: &mut V) { unreachable!() } fn is_mac_call(&self) -> bool { @@ -1117,12 +1117,12 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized { fn pre_flat_map_node_collect_attr(_cfg: &StripUnconfigured<'_>, _attr: &ast::Attribute) {} fn post_flat_map_node_collect_bang(_output: &mut Self::OutputTy, _add_semicolon: AddSemicolon) { } - fn wrap_flat_map_node_noop_flat_map( + fn wrap_flat_map_node_walk_flat_map( node: Self, collector: &mut InvocationCollector<'_, '_>, - noop_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy, + walk_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy, ) -> Result { - Ok(noop_flat_map(node, collector)) + Ok(walk_flat_map(node, collector)) } fn expand_cfg_false( &mut self, @@ -1148,8 +1148,8 @@ impl InvocationCollectorNode for P { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_items() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self, None, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_item(self, None, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, ItemKind::MacCall(..)) @@ -1176,13 +1176,13 @@ impl InvocationCollectorNode for P { fn flatten_outputs(items: impl Iterator) -> Self::OutputTy { items.flatten().collect() } - fn wrap_flat_map_node_noop_flat_map( + fn wrap_flat_map_node_walk_flat_map( mut node: Self, collector: &mut InvocationCollector<'_, '_>, - noop_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy, + walk_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy, ) -> Result { if !matches!(node.kind, ItemKind::Mod(..)) { - return Ok(noop_flat_map(node, collector)); + return Ok(walk_flat_map(node, collector)); } // Work around borrow checker not seeing through `P`'s deref. @@ -1252,7 +1252,7 @@ impl InvocationCollectorNode for P { let orig_dir_ownership = mem::replace(&mut ecx.current_expansion.dir_ownership, dir_ownership); - let res = Ok(noop_flat_map(node, collector)); + let res = Ok(walk_flat_map(node, collector)); collector.cx.current_expansion.dir_ownership = orig_dir_ownership; collector.cx.current_expansion.module = orig_module; @@ -1292,8 +1292,8 @@ impl InvocationCollectorNode for AstNodeWrapper, TraitItemTag> fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_trait_items() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self.wrapped, Some(AssocCtxt::Trait), visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_item(self.wrapped, Some(AssocCtxt::Trait), visitor) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1333,8 +1333,8 @@ impl InvocationCollectorNode for AstNodeWrapper, ImplItemTag> fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_impl_items() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self.wrapped, Some(AssocCtxt::Impl), visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_item(self.wrapped, Some(AssocCtxt::Impl), visitor) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1371,8 +1371,8 @@ impl InvocationCollectorNode for P { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_foreign_items() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self, None, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_item(self, None, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, ForeignItemKind::MacCall(..)) @@ -1394,8 +1394,8 @@ impl InvocationCollectorNode for ast::Variant { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_variants() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_variant(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_variant(self, visitor) } } @@ -1407,8 +1407,8 @@ impl InvocationCollectorNode for ast::FieldDef { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_field_defs() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_field_def(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_field_def(self, visitor) } } @@ -1420,8 +1420,8 @@ impl InvocationCollectorNode for ast::PatField { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_pat_fields() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_pat_field(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_pat_field(self, visitor) } } @@ -1433,8 +1433,8 @@ impl InvocationCollectorNode for ast::ExprField { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_expr_fields() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_expr_field(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_expr_field(self, visitor) } } @@ -1446,8 +1446,8 @@ impl InvocationCollectorNode for ast::Param { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_params() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_param(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_param(self, visitor) } } @@ -1459,8 +1459,8 @@ impl InvocationCollectorNode for ast::GenericParam { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_generic_params() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_generic_param(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_generic_param(self, visitor) } } @@ -1472,8 +1472,8 @@ impl InvocationCollectorNode for ast::Arm { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_arms() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_arm(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_arm(self, visitor) } } @@ -1486,8 +1486,8 @@ impl InvocationCollectorNode for ast::Stmt { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_stmts() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_stmt(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_stmt(self, visitor) } fn is_mac_call(&self) -> bool { match &self.kind { @@ -1560,8 +1560,8 @@ impl InvocationCollectorNode for ast::Crate { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_crate() } - fn noop_visit(&mut self, visitor: &mut V) { - noop_visit_crate(self, visitor) + fn walk(&mut self, visitor: &mut V) { + walk_crate(self, visitor) } fn expand_cfg_false( &mut self, @@ -1586,8 +1586,8 @@ impl InvocationCollectorNode for P { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_ty() } - fn noop_visit(&mut self, visitor: &mut V) { - noop_visit_ty(self, visitor) + fn walk(&mut self, visitor: &mut V) { + walk_ty(self, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, ast::TyKind::MacCall(..)) @@ -1610,8 +1610,8 @@ impl InvocationCollectorNode for P { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_pat() } - fn noop_visit(&mut self, visitor: &mut V) { - noop_visit_pat(self, visitor) + fn walk(&mut self, visitor: &mut V) { + walk_pat(self, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, PatKind::MacCall(..)) @@ -1638,8 +1638,8 @@ impl InvocationCollectorNode for P { fn descr() -> &'static str { "an expression" } - fn noop_visit(&mut self, visitor: &mut V) { - noop_visit_expr(self, visitor) + fn walk(&mut self, visitor: &mut V) { + walk_expr(self, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, ExprKind::MacCall(..)) @@ -1664,8 +1664,8 @@ impl InvocationCollectorNode for AstNodeWrapper, OptExprTag> { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_opt_expr() } - fn noop_flat_map(mut self, visitor: &mut V) -> Self::OutputTy { - noop_visit_expr(&mut self.wrapped, visitor); + fn walk_flat_map(mut self, visitor: &mut V) -> Self::OutputTy { + walk_expr(&mut self.wrapped, visitor); Some(self.wrapped) } fn is_mac_call(&self) -> bool { @@ -1704,8 +1704,8 @@ impl InvocationCollectorNode for AstNodeWrapper, MethodReceiverTag> fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { AstNodeWrapper::new(fragment.make_method_receiver_expr(), MethodReceiverTag) } - fn noop_visit(&mut self, visitor: &mut V) { - noop_visit_expr(&mut self.wrapped, visitor) + fn walk(&mut self, visitor: &mut V) { + walk_expr(&mut self.wrapped, visitor) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, ast::ExprKind::MacCall(..)) @@ -2015,12 +2015,12 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { ); Node::flatten_outputs(single_delegations.map(|item| { let mut item = Node::from_item(item); - assign_id!(self, item.node_id_mut(), || item.noop_flat_map(self)) + assign_id!(self, item.node_id_mut(), || item.walk_flat_map(self)) })) } None => { - match Node::wrap_flat_map_node_noop_flat_map(node, self, |mut node, this| { - assign_id!(this, node.node_id_mut(), || node.noop_flat_map(this)) + match Node::wrap_flat_map_node_walk_flat_map(node, self, |mut node, this| { + assign_id!(this, node.node_id_mut(), || node.walk_flat_map(this)) }) { Ok(output) => output, Err(returned_node) => { @@ -2068,7 +2068,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { } None if node.delegation().is_some() => unreachable!(), None => { - assign_id!(self, node.node_id_mut(), || node.noop_visit(self)) + assign_id!(self, node.node_id_mut(), || node.walk(self)) } }; } @@ -2147,11 +2147,11 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { self.cx.current_expansion.is_trailing_mac = true; // Don't use `assign_id` for this statement - it may get removed // entirely due to a `#[cfg]` on the contained expression - let res = noop_flat_map_stmt(node, self); + let res = walk_flat_map_stmt(node, self); self.cx.current_expansion.is_trailing_mac = false; res } - _ => noop_flat_map_stmt(node, self), + _ => walk_flat_map_stmt(node, self), }; } @@ -2195,7 +2195,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { &mut self.cx.current_expansion.dir_ownership, DirOwnership::UnownedViaBlock, ); - noop_visit_block(node, self); + walk_block(node, self); self.cx.current_expansion.dir_ownership = orig_dir_ownership; } diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 2ed968f57bc..a9884b344c7 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -209,7 +209,7 @@ impl MutVisitor for PlaceholderExpander { if arm.is_placeholder { self.remove(arm.id).make_arms() } else { - noop_flat_map_arm(arm, self) + walk_flat_map_arm(arm, self) } } @@ -217,7 +217,7 @@ impl MutVisitor for PlaceholderExpander { if field.is_placeholder { self.remove(field.id).make_expr_fields() } else { - noop_flat_map_expr_field(field, self) + walk_flat_map_expr_field(field, self) } } @@ -225,7 +225,7 @@ impl MutVisitor for PlaceholderExpander { if fp.is_placeholder { self.remove(fp.id).make_pat_fields() } else { - noop_flat_map_pat_field(fp, self) + walk_flat_map_pat_field(fp, self) } } @@ -236,7 +236,7 @@ impl MutVisitor for PlaceholderExpander { if param.is_placeholder { self.remove(param.id).make_generic_params() } else { - noop_flat_map_generic_param(param, self) + walk_flat_map_generic_param(param, self) } } @@ -244,7 +244,7 @@ impl MutVisitor for PlaceholderExpander { if p.is_placeholder { self.remove(p.id).make_params() } else { - noop_flat_map_param(p, self) + walk_flat_map_param(p, self) } } @@ -252,7 +252,7 @@ impl MutVisitor for PlaceholderExpander { if sf.is_placeholder { self.remove(sf.id).make_field_defs() } else { - noop_flat_map_field_def(sf, self) + walk_flat_map_field_def(sf, self) } } @@ -260,14 +260,14 @@ impl MutVisitor for PlaceholderExpander { if variant.is_placeholder { self.remove(variant.id).make_variants() } else { - noop_flat_map_variant(variant, self) + walk_flat_map_variant(variant, self) } } fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { match item.kind { ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(), - _ => noop_flat_map_item(item, None, self), + _ => walk_flat_map_item(item, None, self), } } @@ -284,7 +284,7 @@ impl MutVisitor for PlaceholderExpander { AssocCtxt::Impl => it.make_impl_items(), } } - _ => noop_flat_map_item(item, Some(ctxt), self), + _ => walk_flat_map_item(item, Some(ctxt), self), } } @@ -294,21 +294,21 @@ impl MutVisitor for PlaceholderExpander { ) -> SmallVec<[P; 1]> { match item.kind { ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(), - _ => noop_flat_map_item(item, None, self), + _ => walk_flat_map_item(item, None, self), } } fn visit_expr(&mut self, expr: &mut P) { match expr.kind { ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_expr(), - _ => noop_visit_expr(expr, self), + _ => walk_expr(expr, self), } } fn visit_method_receiver_expr(&mut self, expr: &mut P) { match expr.kind { ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_method_receiver_expr(), - _ => noop_visit_expr(expr, self), + _ => walk_expr(expr, self), } } @@ -322,7 +322,7 @@ impl MutVisitor for PlaceholderExpander { fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { let (style, mut stmts) = match stmt.kind { ast::StmtKind::MacCall(mac) => (mac.style, self.remove(stmt.id).make_stmts()), - _ => return noop_flat_map_stmt(stmt, self), + _ => return walk_flat_map_stmt(stmt, self), }; if style == ast::MacStmtStyle::Semicolon { @@ -368,14 +368,14 @@ impl MutVisitor for PlaceholderExpander { fn visit_pat(&mut self, pat: &mut P) { match pat.kind { ast::PatKind::MacCall(_) => *pat = self.remove(pat.id).make_pat(), - _ => noop_visit_pat(pat, self), + _ => walk_pat(pat, self), } } fn visit_ty(&mut self, ty: &mut P) { match ty.kind { ast::TyKind::MacCall(_) => *ty = self.remove(ty.id).make_ty(), - _ => noop_visit_ty(ty, self), + _ => walk_ty(ty, self), } } @@ -383,7 +383,7 @@ impl MutVisitor for PlaceholderExpander { if krate.is_placeholder { *krate = self.remove(krate.id).make_crate(); } else { - noop_visit_crate(krate, self) + walk_crate(krate, self) } } } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 2542108728f..e1b34c2564b 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -10,7 +10,7 @@ use super::{ use crate::errors; use crate::maybe_recover_from_interpolated_ty_qpath; -use ast::mut_visit::{noop_visit_expr, MutVisitor}; +use ast::mut_visit::{self, MutVisitor}; use ast::token::IdentIsRaw; use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment, Recovered}; use core::mem; @@ -3939,14 +3939,14 @@ impl MutVisitor for CondChecker<'_> { } } ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, _, _) => { - noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); } ExprKind::Binary(Spanned { node: BinOpKind::Or, span: or_span }, _, _) if let None | Some(NotSupportedOr(_)) = self.forbid_let_reason => { let forbid_let_reason = self.forbid_let_reason; self.forbid_let_reason = Some(NotSupportedOr(or_span)); - noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); self.forbid_let_reason = forbid_let_reason; } ExprKind::Paren(ref inner) @@ -3954,7 +3954,7 @@ impl MutVisitor for CondChecker<'_> { { let forbid_let_reason = self.forbid_let_reason; self.forbid_let_reason = Some(NotSupportedParentheses(inner.span)); - noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); self.forbid_let_reason = forbid_let_reason; } ExprKind::Assign(ref lhs, _, span) => { @@ -3972,7 +3972,7 @@ impl MutVisitor for CondChecker<'_> { } let comparison = self.comparison; self.comparison = Some(errors::MaybeComparison { span: span.shrink_to_hi() }); - noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); self.forbid_let_reason = forbid_let_reason; self.missing_let = missing_let; self.comparison = comparison; @@ -3992,7 +3992,7 @@ impl MutVisitor for CondChecker<'_> { | ExprKind::Paren(_) => { let forbid_let_reason = self.forbid_let_reason; self.forbid_let_reason = Some(OtherForbidden); - noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); self.forbid_let_reason = forbid_let_reason; } ExprKind::Cast(ref mut op, _) | ExprKind::Type(ref mut op, _) => { diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 18d531faeaa..487072e2f51 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -12,7 +12,7 @@ use crate::errors::{ }; use crate::parser::expr::{could_be_unclosed_char_literal, LhsExpr}; use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole}; -use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor}; +use rustc_ast::mut_visit::{walk_pat, MutVisitor}; use rustc_ast::ptr::P; use rustc_ast::token::{self, BinOpToken, Delimiter, Token}; use rustc_ast::{ @@ -810,7 +810,7 @@ impl<'a> Parser<'a> { self.0 = true; *m = Mutability::Mut; } - noop_visit_pat(pat, self); + walk_pat(pat, self); } } diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs index fcc41b51542..1e6b5c1c7f1 100644 --- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs @@ -121,7 +121,7 @@ fn remove_all_parens(pat: &mut P) { struct Visitor; impl MutVisitor for Visitor { fn visit_pat(&mut self, pat: &mut P) { - noop_visit_pat(pat, self); + walk_pat(pat, self); let inner = match &mut pat.kind { Paren(i) => mem::replace(&mut i.kind, Wild), _ => return, @@ -138,7 +138,7 @@ fn insert_necessary_parens(pat: &mut P) { impl MutVisitor for Visitor { fn visit_pat(&mut self, pat: &mut P) { use ast::BindingMode; - noop_visit_pat(pat, self); + walk_pat(pat, self); let target = match &mut pat.kind { // `i @ a | b`, `box a | b`, and `& mut? a | b`. 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) -> bool { impl MutVisitor for Visitor { fn visit_pat(&mut self, p: &mut P) { // This is a bottom up transformation, so recurse first. - noop_visit_pat(p, self); + walk_pat(p, self); // Don't have an or-pattern? Just quit early on. let Or(alternatives) = &mut p.kind else { return }; @@ -189,7 +189,7 @@ fn unnest_or_patterns(pat: &mut P) -> bool { // Deal with `Some(Some(0)) | Some(Some(1))`. if this_level_changed { - noop_visit_pat(p, self); + walk_pat(p, self); } } } diff --git a/tests/ui-fulldeps/pprust-expr-roundtrip.rs b/tests/ui-fulldeps/pprust-expr-roundtrip.rs index 762ad0b79ec..8cb55d420b9 100644 --- a/tests/ui-fulldeps/pprust-expr-roundtrip.rs +++ b/tests/ui-fulldeps/pprust-expr-roundtrip.rs @@ -202,7 +202,7 @@ impl MutVisitor for RemoveParens { ExprKind::Paren(inner) => *e = inner, _ => {} }; - mut_visit::noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); } } @@ -211,7 +211,7 @@ struct AddParens; impl MutVisitor for AddParens { fn visit_expr(&mut self, e: &mut P) { - mut_visit::noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); visit_clobber(e, |e| { P(Expr { id: DUMMY_NODE_ID,