From 748b0a2e35681643abccf99f81a2eaa12c0b1342 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Apr 2024 15:21:16 +1000 Subject: [PATCH] Remove unnecessary `pub`s in `mut_visit.rs`. This makes it clearer what is actually used outside of this crate. --- compiler/rustc_ast/src/mut_visit.rs | 125 +++++++++++++--------------- 1 file changed, 60 insertions(+), 65 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index c4e49d7dbea..8cb13914715 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -335,7 +335,7 @@ pub fn visit_clobber(t: &mut T, f: impl FnOnce(T) -> T) { // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. #[inline] -pub fn visit_vec(elems: &mut Vec, mut visit_elem: F) +fn visit_vec(elems: &mut Vec, mut visit_elem: F) where F: FnMut(&mut T), { @@ -346,7 +346,7 @@ where // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. #[inline] -pub fn visit_thin_vec(elems: &mut ThinVec, mut visit_elem: F) +fn visit_thin_vec(elems: &mut ThinVec, mut visit_elem: F) where F: FnMut(&mut T), { @@ -357,7 +357,7 @@ where // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. #[inline] -pub fn visit_opt(opt: &mut Option, mut visit_elem: F) +fn visit_opt(opt: &mut Option, mut visit_elem: F) where F: FnMut(&mut T), { @@ -367,36 +367,37 @@ where } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_attrs(attrs: &mut AttrVec, vis: &mut T) { +fn visit_attrs(attrs: &mut AttrVec, vis: &mut T) { for attr in attrs.iter_mut() { vis.visit_attribute(attr); } } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_exprs(exprs: &mut Vec>, vis: &mut T) { +#[allow(unused)] +fn visit_exprs(exprs: &mut Vec>, vis: &mut T) { exprs.flat_map_in_place(|expr| vis.filter_map_expr(expr)) } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_thin_exprs(exprs: &mut ThinVec>, vis: &mut T) { +fn visit_thin_exprs(exprs: &mut ThinVec>, vis: &mut T) { exprs.flat_map_in_place(|expr| vis.filter_map_expr(expr)) } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_bounds(bounds: &mut GenericBounds, vis: &mut T) { +fn visit_bounds(bounds: &mut GenericBounds, vis: &mut T) { visit_vec(bounds, |bound| vis.visit_param_bound(bound)); } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_fn_sig(FnSig { header, decl, span }: &mut FnSig, vis: &mut T) { +fn visit_fn_sig(FnSig { header, decl, span }: &mut FnSig, vis: &mut T) { vis.visit_fn_header(header); vis.visit_fn_decl(decl); vis.visit_span(span); } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_attr_args(args: &mut AttrArgs, vis: &mut T) { +fn visit_attr_args(args: &mut AttrArgs, vis: &mut T) { match args { AttrArgs::Empty => {} AttrArgs::Delimited(args) => visit_delim_args(args, vis), @@ -411,7 +412,7 @@ pub fn visit_attr_args(args: &mut AttrArgs, vis: &mut T) { } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_delim_args(args: &mut DelimArgs, vis: &mut T) { +fn visit_delim_args(args: &mut DelimArgs, vis: &mut T) { let DelimArgs { dspan, delim: _, tokens } = args; visit_delim_span(dspan, vis); visit_tts(tokens, vis); @@ -435,7 +436,7 @@ pub fn noop_flat_map_pat_field( smallvec![fp] } -pub fn noop_visit_use_tree(use_tree: &mut UseTree, vis: &mut T) { +fn noop_visit_use_tree(use_tree: &mut UseTree, vis: &mut T) { let UseTree { prefix, kind, span } = use_tree; vis.visit_path(prefix); match kind { @@ -462,7 +463,7 @@ pub fn noop_flat_map_arm(mut arm: Arm, vis: &mut T) -> SmallVec<[ smallvec![arm] } -pub fn noop_visit_constraint( +fn noop_visit_constraint( AssocConstraint { id, ident, gen_args, kind, span }: &mut AssocConstraint, vis: &mut T, ) { @@ -541,7 +542,7 @@ pub fn noop_visit_ty(ty: &mut P, vis: &mut T) { visit_lazy_tts(tokens, vis); } -pub fn noop_visit_foreign_mod(foreign_mod: &mut ForeignMod, vis: &mut T) { +fn noop_visit_foreign_mod(foreign_mod: &mut ForeignMod, vis: &mut T) { let ForeignMod { unsafety, abi: _, items } = foreign_mod; visit_unsafety(unsafety, vis); items.flat_map_in_place(|item| vis.flat_map_foreign_item(item)); @@ -562,11 +563,11 @@ pub fn noop_flat_map_variant( smallvec![variant] } -pub fn noop_visit_ident(Ident { name: _, span }: &mut Ident, vis: &mut T) { +fn noop_visit_ident(Ident { name: _, span }: &mut Ident, vis: &mut T) { vis.visit_span(span); } -pub fn noop_visit_path(Path { segments, span, tokens }: &mut Path, vis: &mut T) { +fn noop_visit_path(Path { segments, span, tokens }: &mut Path, vis: &mut T) { vis.visit_span(span); for PathSegment { ident, id, args } in segments { vis.visit_ident(ident); @@ -576,7 +577,7 @@ pub fn noop_visit_path(Path { segments, span, tokens }: &mut Path visit_lazy_tts(tokens, vis); } -pub fn noop_visit_qself(qself: &mut Option>, vis: &mut T) { +fn noop_visit_qself(qself: &mut Option>, vis: &mut T) { visit_opt(qself, |qself| { let QSelf { ty, path_span, position: _ } = &mut **qself; vis.visit_ty(ty); @@ -584,14 +585,14 @@ pub fn noop_visit_qself(qself: &mut Option>, vis: &mut T }) } -pub fn noop_visit_generic_args(generic_args: &mut GenericArgs, vis: &mut T) { +fn noop_visit_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), } } -pub fn noop_visit_generic_arg(arg: &mut GenericArg, vis: &mut T) { +fn noop_visit_generic_arg(arg: &mut GenericArg, vis: &mut T) { match arg { GenericArg::Lifetime(lt) => vis.visit_lifetime(lt), GenericArg::Type(ty) => vis.visit_ty(ty), @@ -599,7 +600,7 @@ pub fn noop_visit_generic_arg(arg: &mut GenericArg, vis: &mut T) } } -pub fn noop_visit_angle_bracketed_parameter_data( +fn noop_visit_angle_bracketed_parameter_data( data: &mut AngleBracketedArgs, vis: &mut T, ) { @@ -611,7 +612,7 @@ pub fn noop_visit_angle_bracketed_parameter_data( vis.visit_span(span); } -pub fn noop_visit_parenthesized_parameter_data( +fn noop_visit_parenthesized_parameter_data( args: &mut ParenthesizedArgs, vis: &mut T, ) { @@ -621,7 +622,7 @@ pub fn noop_visit_parenthesized_parameter_data( vis.visit_span(span); } -pub fn noop_visit_local(local: &mut P, vis: &mut T) { +fn noop_visit_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); vis.visit_pat(pat); @@ -642,7 +643,7 @@ pub fn noop_visit_local(local: &mut P, vis: &mut T) { visit_lazy_tts(tokens, vis); } -pub fn noop_visit_attribute(attr: &mut Attribute, vis: &mut T) { +fn noop_visit_attribute(attr: &mut Attribute, vis: &mut T) { let Attribute { kind, id: _, style: _, span } = attr; match kind { AttrKind::Normal(normal) => { @@ -658,25 +659,25 @@ pub fn noop_visit_attribute(attr: &mut Attribute, vis: &mut T) { vis.visit_span(span); } -pub fn noop_visit_mac(mac: &mut MacCall, vis: &mut T) { +fn noop_visit_mac(mac: &mut MacCall, vis: &mut T) { let MacCall { path, args } = mac; vis.visit_path(path); visit_delim_args(args, vis); } -pub fn noop_visit_macro_def(macro_def: &mut MacroDef, vis: &mut T) { +fn noop_visit_macro_def(macro_def: &mut MacroDef, vis: &mut T) { let MacroDef { body, macro_rules: _ } = macro_def; visit_delim_args(body, vis); } -pub fn noop_visit_meta_list_item(li: &mut NestedMetaItem, vis: &mut T) { +fn noop_visit_meta_list_item(li: &mut NestedMetaItem, vis: &mut T) { match li { NestedMetaItem::MetaItem(mi) => vis.visit_meta_item(mi), NestedMetaItem::Lit(_lit) => {} } } -pub fn noop_visit_meta_item(mi: &mut MetaItem, vis: &mut T) { +fn noop_visit_meta_item(mi: &mut MetaItem, vis: &mut T) { let MetaItem { path: _, kind, span } = mi; match kind { MetaItemKind::Word => {} @@ -697,7 +698,7 @@ pub fn noop_flat_map_param(mut param: Param, vis: &mut T) -> Smal } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_attr_tt(tt: &mut AttrTokenTree, vis: &mut T) { +fn visit_attr_tt(tt: &mut AttrTokenTree, vis: &mut T) { match tt { AttrTokenTree::Token(token, _) => { visit_token(token, vis); @@ -724,7 +725,7 @@ pub fn visit_attr_tt(tt: &mut AttrTokenTree, vis: &mut T) { } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_tt(tt: &mut TokenTree, vis: &mut T) { +fn visit_tt(tt: &mut TokenTree, vis: &mut T) { match tt { TokenTree::Token(token, _) => { visit_token(token, vis); @@ -738,24 +739,21 @@ pub fn visit_tt(tt: &mut TokenTree, vis: &mut T) { } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_tts(TokenStream(tts): &mut TokenStream, vis: &mut T) { +fn visit_tts(TokenStream(tts): &mut TokenStream, vis: &mut T) { if T::VISIT_TOKENS && !tts.is_empty() { let tts = Lrc::make_mut(tts); visit_vec(tts, |tree| visit_tt(tree, vis)); } } -pub fn visit_attr_tts(AttrTokenStream(tts): &mut AttrTokenStream, vis: &mut T) { +fn visit_attr_tts(AttrTokenStream(tts): &mut AttrTokenStream, vis: &mut T) { if T::VISIT_TOKENS && !tts.is_empty() { let tts = Lrc::make_mut(tts); visit_vec(tts, |tree| visit_attr_tt(tree, vis)); } } -pub fn visit_lazy_tts_opt_mut( - lazy_tts: Option<&mut LazyAttrTokenStream>, - vis: &mut T, -) { +fn visit_lazy_tts_opt_mut(lazy_tts: Option<&mut LazyAttrTokenStream>, vis: &mut T) { if T::VISIT_TOKENS { if let Some(lazy_tts) = lazy_tts { let mut tts = lazy_tts.to_attr_token_stream(); @@ -765,7 +763,7 @@ pub fn visit_lazy_tts_opt_mut( } } -pub fn visit_lazy_tts(lazy_tts: &mut Option, vis: &mut T) { +fn visit_lazy_tts(lazy_tts: &mut Option, vis: &mut T) { visit_lazy_tts_opt_mut(lazy_tts.as_mut(), vis); } @@ -818,7 +816,7 @@ pub fn visit_token(t: &mut Token, vis: &mut T) { // contain multiple items, but decided against it when I looked at // `parse_item_or_view_item` and tried to figure out what I would do with // multiple items there.... -pub fn visit_nonterminal(nt: &mut token::Nonterminal, vis: &mut T) { +fn visit_nonterminal(nt: &mut token::Nonterminal, vis: &mut T) { match nt { token::NtItem(item) => visit_clobber(item, |item| { // This is probably okay, because the only visitors likely to @@ -851,7 +849,7 @@ pub fn visit_nonterminal(nt: &mut token::Nonterminal, vis: &mut T } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_defaultness(defaultness: &mut Defaultness, vis: &mut T) { +fn visit_defaultness(defaultness: &mut Defaultness, vis: &mut T) { match defaultness { Defaultness::Default(span) => vis.visit_span(span), Defaultness::Final => {} @@ -859,7 +857,7 @@ pub fn visit_defaultness(defaultness: &mut Defaultness, vis: &mut } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_unsafety(unsafety: &mut Unsafe, vis: &mut T) { +fn visit_unsafety(unsafety: &mut Unsafe, vis: &mut T) { match unsafety { Unsafe::Yes(span) => vis.visit_span(span), Unsafe::No => {} @@ -867,7 +865,7 @@ pub fn visit_unsafety(unsafety: &mut Unsafe, vis: &mut T) { } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_polarity(polarity: &mut ImplPolarity, vis: &mut T) { +fn visit_polarity(polarity: &mut ImplPolarity, vis: &mut T) { match polarity { ImplPolarity::Positive => {} ImplPolarity::Negative(span) => vis.visit_span(span), @@ -875,14 +873,14 @@ pub fn visit_polarity(polarity: &mut ImplPolarity, vis: &mut T) { } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_constness(constness: &mut Const, vis: &mut T) { +fn visit_constness(constness: &mut Const, vis: &mut T) { match constness { Const::Yes(span) => vis.visit_span(span), Const::No => {} } } -pub fn noop_visit_closure_binder(binder: &mut ClosureBinder, vis: &mut T) { +fn noop_visit_closure_binder(binder: &mut ClosureBinder, vis: &mut T) { match binder { ClosureBinder::NotPresent => {} ClosureBinder::For { span: _, generic_params } => { @@ -891,7 +889,7 @@ pub fn noop_visit_closure_binder(binder: &mut ClosureBinder, vis: } } -pub fn noop_visit_coroutine_kind(coroutine_kind: &mut CoroutineKind, vis: &mut T) { +fn noop_visit_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 } @@ -903,27 +901,27 @@ pub fn noop_visit_coroutine_kind(coroutine_kind: &mut CoroutineKi } } -pub fn noop_visit_fn_decl(decl: &mut P, vis: &mut T) { +fn noop_visit_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); } -pub fn noop_visit_fn_ret_ty(fn_ret_ty: &mut FnRetTy, vis: &mut T) { +fn noop_visit_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), } } -pub fn noop_visit_param_bound(pb: &mut GenericBound, vis: &mut T) { +fn noop_visit_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), } } -pub fn noop_visit_precise_capturing_arg(arg: &mut PreciseCapturingArg, vis: &mut T) { +fn noop_visit_precise_capturing_arg(arg: &mut PreciseCapturingArg, vis: &mut T) { match arg { PreciseCapturingArg::Lifetime(lt) => { vis.visit_lifetime(lt); @@ -960,7 +958,7 @@ pub fn noop_flat_map_generic_param( smallvec![param] } -pub fn noop_visit_label(Label { ident }: &mut Label, vis: &mut T) { +fn noop_visit_label(Label { ident }: &mut Label, vis: &mut T) { vis.visit_ident(ident); } @@ -969,20 +967,20 @@ fn noop_visit_lifetime(Lifetime { id, ident }: &mut Lifetime, vis vis.visit_ident(ident); } -pub fn noop_visit_generics(generics: &mut Generics, vis: &mut T) { +fn noop_visit_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); } -pub fn noop_visit_where_clause(wc: &mut WhereClause, vis: &mut T) { +fn noop_visit_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); } -pub fn noop_visit_where_predicate(pred: &mut WherePredicate, vis: &mut T) { +fn noop_visit_where_predicate(pred: &mut WherePredicate, vis: &mut T) { match pred { WherePredicate::BoundPredicate(bp) => { let WhereBoundPredicate { span, bound_generic_params, bounded_ty, bounds } = bp; @@ -1006,7 +1004,7 @@ pub fn noop_visit_where_predicate(pred: &mut WherePredicate, vis: } } -pub fn noop_visit_variant_data(vdata: &mut VariantData, vis: &mut T) { +fn noop_visit_variant_data(vdata: &mut VariantData, vis: &mut T) { match vdata { VariantData::Struct { fields, .. } => { fields.flat_map_in_place(|field| vis.flat_map_field_def(field)); @@ -1019,12 +1017,12 @@ pub fn noop_visit_variant_data(vdata: &mut VariantData, vis: &mut } } -pub fn noop_visit_trait_ref(TraitRef { path, ref_id }: &mut TraitRef, vis: &mut T) { +fn noop_visit_trait_ref(TraitRef { path, ref_id }: &mut TraitRef, vis: &mut T) { vis.visit_path(path); vis.visit_id(ref_id); } -pub fn noop_visit_poly_trait_ref(p: &mut PolyTraitRef, vis: &mut T) { +fn noop_visit_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); @@ -1058,7 +1056,7 @@ pub fn noop_flat_map_expr_field( smallvec![f] } -pub fn noop_visit_mt(MutTy { ty, mutbl: _ }: &mut MutTy, vis: &mut T) { +fn noop_visit_mt(MutTy { ty, mutbl: _ }: &mut MutTy, vis: &mut T) { vis.visit_ty(ty); } @@ -1219,7 +1217,7 @@ fn visit_const_item( visit_opt(expr, |expr| visitor.visit_expr(expr)); } -pub fn noop_visit_fn_header(header: &mut FnHeader, vis: &mut T) { +fn noop_visit_fn_header(header: &mut FnHeader, vis: &mut T) { let FnHeader { unsafety, coroutine_kind, constness, ext: _ } = header; visit_constness(constness, vis); coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind)); @@ -1337,12 +1335,12 @@ pub fn noop_visit_pat(pat: &mut P, vis: &mut T) { visit_lazy_tts(tokens, vis); } -pub fn noop_visit_anon_const(AnonConst { id, value }: &mut AnonConst, vis: &mut T) { +fn noop_visit_anon_const(AnonConst { id, value }: &mut AnonConst, vis: &mut T) { vis.visit_id(id); vis.visit_expr(value); } -pub fn noop_visit_inline_asm(asm: &mut InlineAsm, vis: &mut T) { +fn noop_visit_inline_asm(asm: &mut InlineAsm, vis: &mut T) { for (op, _) in &mut asm.operands { match op { InlineAsmOperand::In { expr, .. } @@ -1362,7 +1360,7 @@ pub fn noop_visit_inline_asm(asm: &mut InlineAsm, vis: &mut T) { } } -pub fn noop_visit_inline_asm_sym( +fn noop_visit_inline_asm_sym( InlineAsmSym { id, qself, path }: &mut InlineAsmSym, vis: &mut T, ) { @@ -1371,7 +1369,7 @@ pub fn noop_visit_inline_asm_sym( vis.visit_path(path); } -pub fn noop_visit_format_args(fmt: &mut FormatArgs, vis: &mut T) { +fn noop_visit_format_args(fmt: &mut FormatArgs, vis: &mut T) { for arg in fmt.arguments.all_args_mut() { if let FormatArgumentKind::Named(name) = &mut arg.kind { vis.visit_ident(name); @@ -1588,10 +1586,7 @@ pub fn noop_flat_map_stmt( stmts } -pub fn noop_flat_map_stmt_kind( - kind: StmtKind, - vis: &mut T, -) -> SmallVec<[StmtKind; 1]> { +fn noop_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); @@ -1611,7 +1606,7 @@ pub fn noop_flat_map_stmt_kind( } } -pub fn noop_visit_vis(visibility: &mut Visibility, vis: &mut T) { +fn noop_visit_vis(visibility: &mut Visibility, vis: &mut T) { match &mut visibility.kind { VisibilityKind::Public | VisibilityKind::Inherited => {} VisibilityKind::Restricted { path, id, shorthand: _ } => { @@ -1622,7 +1617,7 @@ pub fn noop_visit_vis(visibility: &mut Visibility, vis: &mut T) { vis.visit_span(&mut visibility.span); } -pub fn noop_visit_capture_by(capture_by: &mut CaptureBy, vis: &mut T) { +fn noop_visit_capture_by(capture_by: &mut CaptureBy, vis: &mut T) { match capture_by { CaptureBy::Ref => {} CaptureBy::Value { move_kw } => {