diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index f6b5cd394b6..0fdccb08918 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -350,7 +350,7 @@ pub(crate) struct ModuleMultipleCandidates { #[derive(Diagnostic)] #[diag(expand_trace_macro)] -pub struct TraceMacro { +pub(crate) struct TraceMacro { #[primary_span] pub span: Span, } @@ -402,14 +402,14 @@ pub(crate) struct CustomAttributePanickedHelp { #[derive(Diagnostic)] #[diag(expand_proc_macro_derive_tokens)] -pub struct ProcMacroDeriveTokens { +pub(crate) struct ProcMacroDeriveTokens { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(expand_duplicate_matcher_binding)] -pub struct DuplicateMatcherBinding { +pub(crate) struct DuplicateMatcherBinding { #[primary_span] #[label] pub span: Span, @@ -421,7 +421,7 @@ pub struct DuplicateMatcherBinding { #[diag(expand_missing_fragment_specifier)] #[note] #[help(expand_valid)] -pub struct MissingFragmentSpecifier { +pub(crate) struct MissingFragmentSpecifier { #[primary_span] pub span: Span, #[suggestion( @@ -437,7 +437,7 @@ pub struct MissingFragmentSpecifier { #[derive(Diagnostic)] #[diag(expand_invalid_fragment_specifier)] #[help] -pub struct InvalidFragmentSpecifier { +pub(crate) struct InvalidFragmentSpecifier { #[primary_span] pub span: Span, pub fragment: Ident, @@ -446,7 +446,7 @@ pub struct InvalidFragmentSpecifier { #[derive(Diagnostic)] #[diag(expand_expected_paren_or_brace)] -pub struct ExpectedParenOrBrace<'a> { +pub(crate) struct ExpectedParenOrBrace<'a> { #[primary_span] pub span: Span, pub token: Cow<'a, str>, @@ -479,7 +479,7 @@ pub(crate) struct GlobDelegationTraitlessQpath { #[derive(Diagnostic)] #[diag(expand_proc_macro_back_compat)] #[note] -pub struct ProcMacroBackCompat { +pub(crate) struct ProcMacroBackCompat { pub crate_name: String, pub fixed_version: String, } diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index 4222c9fe906..777044e3f33 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -13,6 +13,7 @@ #![feature(rustdoc_internals)] #![feature(try_blocks)] #![feature(yeet_expr)] +#![warn(unreachable_pub)] // tidy-alphabetical-end extern crate proc_macro as pm; diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index 628c6bfeb79..5778f661622 100644 --- a/compiler/rustc_expand/src/mbe/diagnostics.rs +++ b/compiler/rustc_expand/src/mbe/diagnostics.rs @@ -196,13 +196,14 @@ impl<'dcx> CollectTrackerAndEmitter<'dcx, '_> { } } -/// Currently used by macro_rules! compilation to extract a little information from the `Failure` case. -pub struct FailureForwarder<'matcher> { +/// Currently used by macro_rules! compilation to extract a little information from the `Failure` +/// case. +pub(crate) struct FailureForwarder<'matcher> { expected_token: Option<&'matcher Token>, } impl<'matcher> FailureForwarder<'matcher> { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { expected_token: None } } } diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index e5b9c627429..9011d02da33 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -407,7 +407,7 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool { // Note: the vectors could be created and dropped within `parse_tt`, but to avoid excess // allocations we have a single vector for each kind that is cleared and reused repeatedly. -pub struct TtParser { +pub(crate) struct TtParser { macro_name: Ident, /// The set of current mps to be processed. This should be empty by the end of a successful diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index b2f7c8f5183..5df0aebfe57 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -14,12 +14,11 @@ use crate::mbe::macro_parser::count_metavar_decls; use crate::mbe::{Delimited, KleeneOp, KleeneToken, MetaVarExpr, SequenceRepetition, TokenTree}; const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \ - `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, \ - `literal`, `path`, `meta`, `tt`, `item` and `vis`"; -pub const VALID_FRAGMENT_NAMES_MSG_2021: &str = "valid fragment specifiers are \ - `ident`, `block`, `stmt`, `expr`, `expr_2021`, `pat`, \ - `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, \ - `item` and `vis`"; + `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, \ + `item` and `vis`"; +pub(crate) const VALID_FRAGMENT_NAMES_MSG_2021: &str = "valid fragment specifiers are \ + `ident`, `block`, `stmt`, `expr`, `expr_2021`, `pat`, `ty`, `lifetime`, `literal`, `path`, \ + `meta`, `tt`, `item` and `vis`"; /// Takes a `tokenstream::TokenStream` and returns a `Vec`. Specifically, this /// takes a generic `TokenStream`, such as is used in the rest of the compiler, and returns a diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 1e455d465e4..469bed3cd59 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -191,12 +191,12 @@ pub(crate) fn placeholder( } #[derive(Default)] -pub struct PlaceholderExpander { +pub(crate) struct PlaceholderExpander { expanded_fragments: FxHashMap, } impl PlaceholderExpander { - pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment) { + pub(crate) fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment) { fragment.mut_visit_with(self); self.expanded_fragments.insert(id, fragment); } diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 1438d1ad11f..4ff5da1a4bd 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -414,7 +414,7 @@ impl ToInternal for Level { } } -pub struct FreeFunctions; +pub(crate) struct FreeFunctions; pub(crate) struct Rustc<'a, 'b> { ecx: &'a mut ExtCtxt<'b>, @@ -426,7 +426,7 @@ pub(crate) struct Rustc<'a, 'b> { } impl<'a, 'b> Rustc<'a, 'b> { - pub fn new(ecx: &'a mut ExtCtxt<'b>) -> Self { + pub(crate) fn new(ecx: &'a mut ExtCtxt<'b>) -> Self { let expn_data = ecx.current_expansion.id.expn_data(); Rustc { def_site: ecx.with_def_site_ctxt(expn_data.def_site),