From 15e71b6e43e28ffaa9db70c39fdf82be062e5cfd Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Apr 2024 10:46:43 +1000 Subject: [PATCH 1/6] Make `LazyAttrTokenStream::encode` panic. It's unreachable, because AST JSON printing support was removed some time ago. --- compiler/rustc_ast/src/tokenstream.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index 880f92bbe7b..08d65a5ffa5 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -140,9 +140,8 @@ impl fmt::Debug for LazyAttrTokenStream { } impl Encodable for LazyAttrTokenStream { - fn encode(&self, s: &mut S) { - // Used by AST json printing. - Encodable::encode(&self.to_attr_token_stream(), s); + fn encode(&self, _s: &mut S) { + panic!("Attempted to encode LazyAttrTokenStream"); } } From d5ec9b458a4a584164cbfc6a53298560091ecd8c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Apr 2024 13:18:17 +1000 Subject: [PATCH 2/6] Remove `MetaItemKind::value_str`. `MetaItem::value_str` is good enough. And this makes `MetaItem::value_str` more like `MetaItem::meta_item_list` and `name_value_literal`. --- compiler/rustc_ast/src/attr/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 5e3fc7e3357..e67c5fd9a5a 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -298,7 +298,10 @@ impl MetaItem { } pub fn value_str(&self) -> Option { - self.kind.value_str() + match &self.kind { + MetaItemKind::NameValue(v) => v.kind.str(), + _ => None, + } } fn from_tokens<'a, I>(tokens: &mut iter::Peekable) -> Option @@ -362,13 +365,6 @@ impl MetaItem { } impl MetaItemKind { - pub fn value_str(&self) -> Option { - match self { - MetaItemKind::NameValue(v) => v.kind.str(), - _ => None, - } - } - fn list_from_tokens(tokens: TokenStream) -> Option> { let mut tokens = tokens.trees().peekable(); let mut result = ThinVec::new(); From 8d4655d9ec9befc5cdcbb8d7a2961a75aecfc145 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Apr 2024 14:25:59 +1000 Subject: [PATCH 3/6] Rename `NestedMetaItem::name_value_literal`. It's a highly misleading name, because it's completely different to `MetaItem::name_value_literal`. Specifically, it doesn't match `MetaItemKind::NameValue` (e.g. `#[foo = 3]`), it matches `MetaItemKind::List` (e.g. `#[foo(3)]`). --- compiler/rustc_ast/src/attr/mod.rs | 5 +++-- compiler/rustc_attr/src/builtin.rs | 2 +- compiler/rustc_codegen_ssa/src/codegen_attrs.rs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index e67c5fd9a5a..0f12fd31975 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -464,8 +464,9 @@ impl NestedMetaItem { self.meta_item().and_then(|meta_item| meta_item.meta_item_list()) } - /// Returns a name and single literal value tuple of the `MetaItem`. - pub fn name_value_literal(&self) -> Option<(Symbol, &MetaItemLit)> { + /// If it's a singleton list of the form `foo(lit)`, returns the `foo` and + /// the `lit`. + pub fn singleton_lit_list(&self) -> Option<(Symbol, &MetaItemLit)> { self.meta_item().and_then(|meta_item| { meta_item.meta_item_list().and_then(|meta_item_list| { if meta_item_list.len() == 1 diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 439f13e7635..1c2077372e1 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -986,7 +986,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec { recognised = true; acc.push(h); } - } else if let Some((name, value)) = item.name_value_literal() { + } else if let Some((name, value)) = item.singleton_lit_list() { let mut literal_error = None; let mut err_span = item.span(); if name == sym::align { diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 9c9e134f033..c28b0d644e6 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -435,7 +435,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { sym::repr => { codegen_fn_attrs.alignment = if let Some(items) = attr.meta_item_list() && let [item] = items.as_slice() - && let Some((sym::align, literal)) = item.name_value_literal() + && let Some((sym::align, literal)) = item.singleton_lit_list() { rustc_attr::parse_alignment(&literal.kind) .map_err(|msg| { From 748b0a2e35681643abccf99f81a2eaa12c0b1342 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Apr 2024 15:21:16 +1000 Subject: [PATCH 4/6] 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 } => { From 78e7c7b9f9f6a671255ff0fb88b5a6fd6dbc7a58 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Apr 2024 09:45:47 +1000 Subject: [PATCH 5/6] Whitespace fixes. --- compiler/rustc_session/src/options.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index d5108058948..6a556e2a1f5 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1,5 +1,4 @@ use crate::config::*; - use crate::search_paths::SearchPath; use crate::utils::NativeLib; use crate::{lint, EarlyDiagCtxt}; @@ -8,20 +7,17 @@ use rustc_data_structures::profiling::TimePassesFormat; use rustc_data_structures::stable_hasher::Hash64; use rustc_errors::ColorConfig; use rustc_errors::{LanguageIdentifier, TerminalUrl}; +use rustc_feature::UnstableFeatures; +use rustc_span::edition::Edition; +use rustc_span::RealFileName; +use rustc_span::SourceFileHashAlgorithm; use rustc_target::spec::{ CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, SanitizerSet, WasmCAbi, }; use rustc_target::spec::{ RelocModel, RelroLevel, SplitDebuginfo, StackProtector, TargetTriple, TlsModel, }; - -use rustc_feature::UnstableFeatures; -use rustc_span::edition::Edition; -use rustc_span::RealFileName; -use rustc_span::SourceFileHashAlgorithm; - use std::collections::BTreeMap; - use std::hash::{DefaultHasher, Hasher}; use std::num::{IntErrorKind, NonZero}; use std::path::PathBuf; @@ -118,8 +114,8 @@ top_level_options!( /// incremental compilation cache before proceeding. /// /// - `[TRACKED_NO_CRATE_HASH]` - /// Same as `[TRACKED]`, but will not affect the crate hash. This is useful for options that only - /// affect the incremental cache. + /// Same as `[TRACKED]`, but will not affect the crate hash. This is useful for options that + /// only affect the incremental cache. /// /// - `[UNTRACKED]` /// Incremental compilation is not influenced by this option. From 2ae0765ffb743de9845ee953bb6020db866e5b63 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 25 Apr 2024 10:14:17 +1000 Subject: [PATCH 6/6] Add comments about attribute tokens. This clarifies something that has puzzled me for some time. --- compiler/rustc_ast/src/ast.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index bddb50568d4..dc3377f6bad 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2786,6 +2786,7 @@ pub enum AttrKind { #[derive(Clone, Encodable, Decodable, Debug)] pub struct NormalAttr { pub item: AttrItem, + // Tokens for the full attribute, e.g. `#[foo]`, `#![bar]`. pub tokens: Option, } @@ -2802,6 +2803,7 @@ impl NormalAttr { pub struct AttrItem { pub path: Path, pub args: AttrArgs, + // Tokens for the meta item, e.g. just the `foo` within `#[foo]` or `#![foo]`. pub tokens: Option, }