Skip to content

Commit

Permalink
Add warn(unreachable_pub) to rustc_macros.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Aug 29, 2024
1 parent 6cf068d commit 4b92682
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_macros/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use synstructure::Structure;
///
/// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`:
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html>
pub fn diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
pub(super) fn diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
s.underscore_const(true);
DiagnosticDerive::new(s).into_tokens()
}
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
///
/// See rustc dev guide for more examples on using the `#[derive(LintDiagnostic)]`:
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html#reference>
pub fn lint_diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
pub(super) fn lint_diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
s.underscore_const(true);
LintDiagnosticDerive::new(s).into_tokens()
}
Expand Down Expand Up @@ -153,7 +153,7 @@ pub fn lint_diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
///
/// diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident });
/// ```
pub fn subdiagnostic_derive(mut s: Structure<'_>) -> TokenStream {
pub(super) fn subdiagnostic_derive(mut s: Structure<'_>) -> TokenStream {
s.underscore_const(true);
SubdiagnosticDerive::new().into_tokens(s)
}
1 change: 1 addition & 0 deletions compiler/rustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_span)]
#![feature(proc_macro_tracked_env)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end

use proc_macro::TokenStream;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/lift.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use quote::quote;
use syn::parse_quote;

pub fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
pub(super) fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
s.add_bounds(synstructure::AddBounds::Generics);
s.bind_with(|_| synstructure::BindStyle::Move);
s.underscore_const(true);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ fn add_query_desc_cached_impl(
});
}

pub fn rustc_queries(input: TokenStream) -> TokenStream {
pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
let queries = parse_macro_input!(input as List<Query>);

let mut query_stream = quote! {};
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_macros/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use quote::{quote, quote_spanned};
use syn::parse_quote;
use syn::spanned::Spanned;

pub fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
pub(super) fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
let decoder_ty = quote! { __D };
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
Expand All @@ -20,7 +20,7 @@ pub fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
decodable_body(s, decoder_ty)
}

pub fn meta_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
pub(super) fn meta_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
s.add_impl_generic(parse_quote! { 'tcx });
}
Expand All @@ -32,7 +32,7 @@ pub fn meta_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
decodable_body(s, decoder_ty)
}

pub fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
pub(super) fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
let decoder_ty = quote! { __D };
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_span::SpanDecoder });
s.add_bounds(synstructure::AddBounds::Generics);
Expand All @@ -41,7 +41,7 @@ pub fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::Toke
decodable_body(s, decoder_ty)
}

pub fn decodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
pub(super) fn decodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
let decoder_ty = quote! { __D };
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_serialize::Decoder });
s.add_bounds(synstructure::AddBounds::Generics);
Expand Down Expand Up @@ -123,7 +123,7 @@ fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream {
quote_spanned! { field_span=> #decode_inner_method(#__decoder) }
}

pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
pub(super) fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
Expand All @@ -140,7 +140,7 @@ pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
encodable_body(s, encoder_ty, false)
}

pub fn meta_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
pub(super) fn meta_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
s.add_impl_generic(parse_quote! { 'tcx });
}
Expand All @@ -152,7 +152,7 @@ pub fn meta_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
encodable_body(s, encoder_ty, true)
}

pub fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
pub(super) fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
let encoder_ty = quote! { __E };
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_span::SpanEncoder });
s.add_bounds(synstructure::AddBounds::Generics);
Expand All @@ -161,7 +161,7 @@ pub fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::Toke
encodable_body(s, encoder_ty, false)
}

pub fn encodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
pub(super) fn encodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
let encoder_ty = quote! { __E };
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_serialize::Encoder });
s.add_bounds(synstructure::AddBounds::Generics);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Errors {
}
}

pub fn symbols(input: TokenStream) -> TokenStream {
pub(super) fn symbols(input: TokenStream) -> TokenStream {
let (mut output, errors) = symbols_with_errors(input);

// If we generated any errors, then report them as compiler_error!() macro calls.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/type_foldable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use quote::{quote, ToTokens};
use syn::parse_quote;

pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
pub(super) fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
if let syn::Data::Union(_) = s.ast().data {
panic!("cannot derive on union")
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/type_visitable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use quote::quote;
use syn::parse_quote;

pub fn type_visitable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
pub(super) fn type_visitable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
if let syn::Data::Union(_) = s.ast().data {
panic!("cannot derive on union")
}
Expand Down

0 comments on commit 4b92682

Please sign in to comment.