From 4b92682530769237564a440c1968feb15fc89709 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 09:01:17 +1000 Subject: [PATCH 01/15] Add `warn(unreachable_pub)` to `rustc_macros`. --- compiler/rustc_macros/src/diagnostics/mod.rs | 6 +++--- compiler/rustc_macros/src/lib.rs | 1 + compiler/rustc_macros/src/lift.rs | 2 +- compiler/rustc_macros/src/query.rs | 2 +- compiler/rustc_macros/src/serialize.rs | 16 ++++++++-------- compiler/rustc_macros/src/symbols.rs | 2 +- compiler/rustc_macros/src/type_foldable.rs | 2 +- compiler/rustc_macros/src/type_visitable.rs | 2 +- 8 files changed, 17 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/mod.rs b/compiler/rustc_macros/src/diagnostics/mod.rs index 134045d0644c0..0f7b89215097e 100644 --- a/compiler/rustc_macros/src/diagnostics/mod.rs +++ b/compiler/rustc_macros/src/diagnostics/mod.rs @@ -55,7 +55,7 @@ use synstructure::Structure; /// /// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`: /// -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() } @@ -102,7 +102,7 @@ pub fn diagnostic_derive(mut s: Structure<'_>) -> TokenStream { /// /// See rustc dev guide for more examples on using the `#[derive(LintDiagnostic)]`: /// -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() } @@ -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) } diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 929bc2df6f6b5..f46c795b9565c 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -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; diff --git a/compiler/rustc_macros/src/lift.rs b/compiler/rustc_macros/src/lift.rs index 627f4088d5f5c..bf4a7665ceb88 100644 --- a/compiler/rustc_macros/src/lift.rs +++ b/compiler/rustc_macros/src/lift.rs @@ -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); diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index ceff1da976364..886a38c8ff252 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -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); let mut query_stream = quote! {}; diff --git a/compiler/rustc_macros/src/serialize.rs b/compiler/rustc_macros/src/serialize.rs index 7b5dd1601c1f6..e481908b0061a 100644 --- a/compiler/rustc_macros/src/serialize.rs +++ b/compiler/rustc_macros/src/serialize.rs @@ -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! { > } @@ -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 }); } @@ -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); @@ -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); @@ -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! { > } } else if s.ast().generics.type_params().any(|ty| ty.ident == "I") { @@ -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 }); } @@ -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); @@ -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); diff --git a/compiler/rustc_macros/src/symbols.rs b/compiler/rustc_macros/src/symbols.rs index 6074c93d59c5d..341186ac1ca3a 100644 --- a/compiler/rustc_macros/src/symbols.rs +++ b/compiler/rustc_macros/src/symbols.rs @@ -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. diff --git a/compiler/rustc_macros/src/type_foldable.rs b/compiler/rustc_macros/src/type_foldable.rs index 5617c53b119ee..8ddfa96e0952f 100644 --- a/compiler/rustc_macros/src/type_foldable.rs +++ b/compiler/rustc_macros/src/type_foldable.rs @@ -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") } diff --git a/compiler/rustc_macros/src/type_visitable.rs b/compiler/rustc_macros/src/type_visitable.rs index 94e86e0e246fe..2ea8c2927f6da 100644 --- a/compiler/rustc_macros/src/type_visitable.rs +++ b/compiler/rustc_macros/src/type_visitable.rs @@ -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") } From 05e07381d07fc097be5922114adf4f40e0625d03 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 09:10:19 +1000 Subject: [PATCH 02/15] Add `warn(unreachable_pub)` to `rustc_metadata`. --- compiler/rustc_macros/src/serialize.rs | 24 ++++++++++++++----- compiler/rustc_macros/src/type_visitable.rs | 4 +++- compiler/rustc_metadata/src/lib.rs | 1 + compiler/rustc_metadata/src/rmeta/decoder.rs | 10 ++++---- .../src/rmeta/def_path_hash_map.rs | 2 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_macros/src/serialize.rs b/compiler/rustc_macros/src/serialize.rs index e481908b0061a..2c33a0ac0aafe 100644 --- a/compiler/rustc_macros/src/serialize.rs +++ b/compiler/rustc_macros/src/serialize.rs @@ -3,7 +3,9 @@ use quote::{quote, quote_spanned}; use syn::parse_quote; use syn::spanned::Spanned; -pub(super) 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! { > } @@ -20,7 +22,9 @@ pub(super) fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_ decodable_body(s, decoder_ty) } -pub(super) 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 }); } @@ -41,7 +45,9 @@ pub(super) fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro decodable_body(s, decoder_ty) } -pub(super) 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); @@ -123,7 +129,9 @@ fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream { quote_spanned! { field_span=> #decode_inner_method(#__decoder) } } -pub(super) 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! { > } } else if s.ast().generics.type_params().any(|ty| ty.ident == "I") { @@ -140,7 +148,9 @@ pub(super) fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_ encodable_body(s, encoder_ty, false) } -pub(super) 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 }); } @@ -161,7 +171,9 @@ pub(super) fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro encodable_body(s, encoder_ty, false) } -pub(super) 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); diff --git a/compiler/rustc_macros/src/type_visitable.rs b/compiler/rustc_macros/src/type_visitable.rs index 2ea8c2927f6da..527ca26c0eb10 100644 --- a/compiler/rustc_macros/src/type_visitable.rs +++ b/compiler/rustc_macros/src/type_visitable.rs @@ -1,7 +1,9 @@ use quote::quote; use syn::parse_quote; -pub(super) 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") } diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index acaf9fb0fc32a..c798ca00bcce2 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -16,6 +16,7 @@ #![feature(proc_macro_internals)] #![feature(rustdoc_internals)] #![feature(trusted_len)] +#![warn(unreachable_pub)] // tidy-alphabetical-end extern crate proc_macro; diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 7321e2c760cef..09aea2337185b 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -56,13 +56,13 @@ impl std::ops::Deref for MetadataBlob { impl MetadataBlob { /// Runs the [`MemDecoder`] validation and if it passes, constructs a new [`MetadataBlob`]. - pub fn new(slice: OwnedSlice) -> Result { + pub(crate) fn new(slice: OwnedSlice) -> Result { if MemDecoder::new(&slice, 0).is_ok() { Ok(Self(slice)) } else { Err(()) } } /// Since this has passed the validation of [`MetadataBlob::new`], this returns bytes which are /// known to pass the [`MemDecoder`] validation. - pub fn bytes(&self) -> &OwnedSlice { + pub(crate) fn bytes(&self) -> &OwnedSlice { &self.0 } } @@ -332,12 +332,12 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> { } #[inline] - pub fn blob(&self) -> &'a MetadataBlob { + pub(crate) fn blob(&self) -> &'a MetadataBlob { self.blob } #[inline] - pub fn cdata(&self) -> CrateMetadataRef<'a> { + fn cdata(&self) -> CrateMetadataRef<'a> { debug_assert!(self.cdata.is_some(), "missing CrateMetadata in DecodeContext"); self.cdata.unwrap() } @@ -377,7 +377,7 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> { } #[inline] - pub fn read_raw_bytes(&mut self, len: usize) -> &[u8] { + fn read_raw_bytes(&mut self, len: usize) -> &[u8] { self.opaque.read_raw_bytes(len) } } diff --git a/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs b/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs index 01fbf37788f9c..19369425f8161 100644 --- a/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs +++ b/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs @@ -17,7 +17,7 @@ parameterized_over_tcx! { impl DefPathHashMapRef<'_> { #[inline] - pub fn def_path_hash_to_def_index(&self, def_path_hash: &DefPathHash) -> DefIndex { + pub(crate) fn def_path_hash_to_def_index(&self, def_path_hash: &DefPathHash) -> DefIndex { match *self { DefPathHashMapRef::OwnedFromMetadata(ref map) => { map.get(&def_path_hash.local_hash()).unwrap() diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index fbcfbd3befa94..d9a844ad8374c 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2309,7 +2309,7 @@ fn encode_root_position(mut file: &File, pos: usize) -> Result<(), std::io::Erro Ok(()) } -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { doc_link_resolutions: |tcx, def_id| { tcx.resolutions(()) From 938daf6033514c190957349354f0c89264370a41 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 09:59:05 +1000 Subject: [PATCH 03/15] Add `warn(unreachable_pub)` to `rustc_middle`. I am surprised the diff is so small for this enormous crate. --- compiler/rustc_middle/src/dep_graph/dep_node.rs | 5 +++-- compiler/rustc_middle/src/lib.rs | 1 + compiler/rustc_middle/src/mir/basic_blocks.rs | 4 ++-- compiler/rustc_middle/src/mir/generic_graph.rs | 2 +- .../rustc_middle/src/mir/interpret/allocation/init_mask.rs | 2 +- compiler/rustc_middle/src/mir/mono.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 9ebe4a57b0297..2d47d1d19afb9 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -61,8 +61,9 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalModDefId, ModDefId, LO use rustc_hir::definitions::DefPathHash; use rustc_hir::{HirId, ItemLocalId, OwnerId}; pub use rustc_query_system::dep_graph::dep_node::DepKind; +pub use rustc_query_system::dep_graph::DepNode; use rustc_query_system::dep_graph::FingerprintStyle; -pub use rustc_query_system::dep_graph::{DepContext, DepNode, DepNodeParams}; +pub(crate) use rustc_query_system::dep_graph::{DepContext, DepNodeParams}; use rustc_span::symbol::Symbol; use crate::mir::mono::MonoItem; @@ -101,7 +102,7 @@ macro_rules! define_dep_nodes { // This checks that the discriminants of the variants have been assigned consecutively // from 0 so that they can be used as a dense index. - pub const DEP_KIND_VARIANTS: u16 = { + pub(crate) const DEP_KIND_VARIANTS: u16 = { let deps = &[$(dep_kinds::$variant,)*]; let mut i = 0; while i < deps.len() { diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 32f79ff72349d..2a85f85a9f4eb 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -62,6 +62,7 @@ #![feature(try_blocks)] #![feature(type_alias_impl_trait)] #![feature(yeet_expr)] +#![warn(unreachable_pub)] // tidy-alphabetical-end #[cfg(test)] diff --git a/compiler/rustc_middle/src/mir/basic_blocks.rs b/compiler/rustc_middle/src/mir/basic_blocks.rs index c08bfc1fa95f4..183b898253e50 100644 --- a/compiler/rustc_middle/src/mir/basic_blocks.rs +++ b/compiler/rustc_middle/src/mir/basic_blocks.rs @@ -18,9 +18,9 @@ pub struct BasicBlocks<'tcx> { } // Typically 95%+ of basic blocks have 4 or fewer predecessors. -pub type Predecessors = IndexVec>; +type Predecessors = IndexVec>; -pub type SwitchSources = FxHashMap<(BasicBlock, BasicBlock), SmallVec<[Option; 1]>>; +type SwitchSources = FxHashMap<(BasicBlock, BasicBlock), SmallVec<[Option; 1]>>; #[derive(Clone, Default, Debug)] struct Cache { diff --git a/compiler/rustc_middle/src/mir/generic_graph.rs b/compiler/rustc_middle/src/mir/generic_graph.rs index 51e26ab7984cf..a52ec58a1ee69 100644 --- a/compiler/rustc_middle/src/mir/generic_graph.rs +++ b/compiler/rustc_middle/src/mir/generic_graph.rs @@ -2,7 +2,7 @@ use gsgdt::{Edge, Graph, Node, NodeStyle}; use rustc_middle::mir::*; /// Convert an MIR function into a gsgdt Graph -pub fn mir_fn_to_generic_graph<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Graph { +pub(crate) fn mir_fn_to_generic_graph<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Graph { let def_id = body.source.def_id(); let def_name = graphviz_safe_def_name(def_id); let graph_name = format!("Mir_{def_name}"); diff --git a/compiler/rustc_middle/src/mir/interpret/allocation/init_mask.rs b/compiler/rustc_middle/src/mir/interpret/allocation/init_mask.rs index 1d2a82c575a34..dfaf96e14f662 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation/init_mask.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation/init_mask.rs @@ -243,7 +243,7 @@ impl hash::Hash for InitMaskMaterialized { } impl InitMaskMaterialized { - pub const BLOCK_SIZE: u64 = 64; + const BLOCK_SIZE: u64 = 64; fn new(size: Size, state: bool) -> Self { let mut m = InitMaskMaterialized { blocks: vec![] }; diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 1d94c364ae3af..69b5e0a79c7fa 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -396,7 +396,7 @@ impl<'tcx> CodegenUnit<'tcx> { // The codegen tests rely on items being process in the same order as // they appear in the file, so for local items, we sort by node_id first #[derive(PartialEq, Eq, PartialOrd, Ord)] - pub struct ItemSortKey<'tcx>(Option, SymbolName<'tcx>); + struct ItemSortKey<'tcx>(Option, SymbolName<'tcx>); fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>) -> ItemSortKey<'tcx> { ItemSortKey( diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 8effb67a1f695..70df205d8932b 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2190,7 +2190,7 @@ macro_rules! sty_debug_print { all_infer: usize, } - pub fn go(fmt: &mut std::fmt::Formatter<'_>, tcx: TyCtxt<'_>) -> std::fmt::Result { + pub(crate) fn go(fmt: &mut std::fmt::Formatter<'_>, tcx: TyCtxt<'_>) -> std::fmt::Result { let mut total = DebugStat { total: 0, lt_infer: 0, From c16e2899dc550b2bc3d04f25eae69c87a3b83824 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 10:13:19 +1000 Subject: [PATCH 04/15] Add `warn(unreachable_pub)` to `rustc_mir_build`. --- compiler/rustc_mir_build/src/check_unsafety.rs | 2 +- compiler/rustc_mir_build/src/lib.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 60cd49b88b43d..4ce796cea7ad3 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -1027,7 +1027,7 @@ impl UnsafeOpKind { } } -pub fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) { +pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) { // Closures and inline consts are handled by their owner, if it has a body // Also, don't safety check custom MIR if tcx.is_typeck_child(def.to_def_id()) || tcx.has_attr(def, sym::custom_mir) { diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs index 66004179b10b1..3dbb552cdbbef 100644 --- a/compiler/rustc_mir_build/src/lib.rs +++ b/compiler/rustc_mir_build/src/lib.rs @@ -8,6 +8,7 @@ #![feature(if_let_guard)] #![feature(let_chains)] #![feature(try_blocks)] +#![warn(unreachable_pub)] // tidy-alphabetical-end mod build; From 8a8dd3f33e8c79bc5c1f06009e87ff120900b5c0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 10:25:30 +1000 Subject: [PATCH 05/15] Add `warn(unreachable_pub)` to `rustc_mir_dataflow`. --- compiler/rustc_mir_dataflow/src/framework/engine.rs | 2 +- compiler/rustc_mir_dataflow/src/framework/mod.rs | 4 ++-- compiler/rustc_mir_dataflow/src/lib.rs | 1 + compiler/rustc_mir_dataflow/src/move_paths/abs_domain.rs | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_mir_dataflow/src/framework/engine.rs b/compiler/rustc_mir_dataflow/src/framework/engine.rs index 364a416480fed..0bab03b027161 100644 --- a/compiler/rustc_mir_dataflow/src/framework/engine.rs +++ b/compiler/rustc_mir_dataflow/src/framework/engine.rs @@ -24,7 +24,7 @@ use crate::errors::{ }; use crate::framework::BitSetExt; -pub type EntrySets<'tcx, A> = IndexVec>::Domain>; +type EntrySets<'tcx, A> = IndexVec>::Domain>; /// A dataflow analysis that has converged to fixpoint. #[derive(Clone)] diff --git a/compiler/rustc_mir_dataflow/src/framework/mod.rs b/compiler/rustc_mir_dataflow/src/framework/mod.rs index 6eaed0f775337..6da3a20dc02c3 100644 --- a/compiler/rustc_mir_dataflow/src/framework/mod.rs +++ b/compiler/rustc_mir_dataflow/src/framework/mod.rs @@ -510,7 +510,7 @@ impl GenKill for lattice::Dual> { // NOTE: DO NOT CHANGE VARIANT ORDER. The derived `Ord` impls rely on the current order. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] -pub enum Effect { +enum Effect { /// The "before" effect (e.g., `apply_before_statement_effect`) for a statement (or /// terminator). Before, @@ -520,7 +520,7 @@ pub enum Effect { } impl Effect { - pub const fn at_index(self, statement_index: usize) -> EffectIndex { + const fn at_index(self, statement_index: usize) -> EffectIndex { EffectIndex { effect: self, statement_index } } } diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index 8708bebeeb087..9385b52103f69 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -5,6 +5,7 @@ #![feature(exact_size_is_empty)] #![feature(let_chains)] #![feature(try_blocks)] +#![warn(unreachable_pub)] // tidy-alphabetical-end use rustc_middle::ty; diff --git a/compiler/rustc_mir_dataflow/src/move_paths/abs_domain.rs b/compiler/rustc_mir_dataflow/src/move_paths/abs_domain.rs index 2a7f23ef6d251..df4c0593246cf 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/abs_domain.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/abs_domain.rs @@ -15,12 +15,12 @@ use rustc_middle::mir::{Local, Operand, PlaceElem, ProjectionElem}; use rustc_middle::ty::Ty; #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] -pub struct AbstractOperand; +pub(crate) struct AbstractOperand; #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] -pub struct AbstractType; -pub type AbstractElem = ProjectionElem; +pub(crate) struct AbstractType; +pub(crate) type AbstractElem = ProjectionElem; -pub trait Lift { +pub(crate) trait Lift { type Abstract; fn lift(&self) -> Self::Abstract; } From e3062147deca0399ba533bd967532cbf4f419abf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 15:08:07 +1000 Subject: [PATCH 06/15] Add `warn(unreachable_pub)` to `rustc_monomorphize`. --- compiler/rustc_monomorphize/src/collector.rs | 16 ++++++++++------ compiler/rustc_monomorphize/src/errors.rs | 18 +++++++++--------- compiler/rustc_monomorphize/src/lib.rs | 1 + .../rustc_monomorphize/src/partitioning.rs | 2 +- .../rustc_monomorphize/src/polymorphize.rs | 2 +- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 36fb2e89af141..9c820b888d910 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -242,12 +242,12 @@ use tracing::{debug, instrument, trace}; use crate::errors::{self, EncounteredErrorWhileInstantiating, NoOptimizedMir, RecursionLimit}; #[derive(PartialEq)] -pub enum MonoItemCollectionStrategy { +pub(crate) enum MonoItemCollectionStrategy { Eager, Lazy, } -pub struct UsageMap<'tcx> { +pub(crate) struct UsageMap<'tcx> { // Maps every mono item to the mono items used by it. used_map: UnordMap, Vec>>, @@ -306,13 +306,17 @@ impl<'tcx> UsageMap<'tcx> { assert!(self.used_map.insert(user_item, used_items).is_none()); } - pub fn get_user_items(&self, item: MonoItem<'tcx>) -> &[MonoItem<'tcx>] { + pub(crate) fn get_user_items(&self, item: MonoItem<'tcx>) -> &[MonoItem<'tcx>] { self.user_map.get(&item).map(|items| items.as_slice()).unwrap_or(&[]) } /// Internally iterate over all inlined items used by `item`. - pub fn for_each_inlined_used_item(&self, tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>, mut f: F) - where + pub(crate) fn for_each_inlined_used_item( + &self, + tcx: TyCtxt<'tcx>, + item: MonoItem<'tcx>, + mut f: F, + ) where F: FnMut(MonoItem<'tcx>), { let used_items = self.used_map.get(&item).unwrap(); @@ -1615,6 +1619,6 @@ pub(crate) fn collect_crate_mono_items<'tcx>( (mono_items, state.usage_map.into_inner()) } -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { providers.hooks.should_codegen_locally = should_codegen_locally; } diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs index c97e07ee3ba67..d5fae6e23cb45 100644 --- a/compiler/rustc_monomorphize/src/errors.rs +++ b/compiler/rustc_monomorphize/src/errors.rs @@ -8,7 +8,7 @@ use crate::fluent_generated as fluent; #[derive(Diagnostic)] #[diag(monomorphize_recursion_limit)] -pub struct RecursionLimit { +pub(crate) struct RecursionLimit { #[primary_span] pub span: Span, pub shrunk: String, @@ -22,13 +22,13 @@ pub struct RecursionLimit { #[derive(Diagnostic)] #[diag(monomorphize_no_optimized_mir)] -pub struct NoOptimizedMir { +pub(crate) struct NoOptimizedMir { #[note] pub span: Span, pub crate_name: Symbol, } -pub struct UnusedGenericParamsHint { +pub(crate) struct UnusedGenericParamsHint { pub span: Span, pub param_spans: Vec, pub param_names: Vec, @@ -53,7 +53,7 @@ impl Diagnostic<'_, G> for UnusedGenericParamsHint { #[derive(LintDiagnostic)] #[diag(monomorphize_large_assignments)] #[note] -pub struct LargeAssignmentsLint { +pub(crate) struct LargeAssignmentsLint { #[label] pub span: Span, pub size: u64, @@ -62,7 +62,7 @@ pub struct LargeAssignmentsLint { #[derive(Diagnostic)] #[diag(monomorphize_symbol_already_defined)] -pub struct SymbolAlreadyDefined { +pub(crate) struct SymbolAlreadyDefined { #[primary_span] pub span: Option, pub symbol: String, @@ -70,13 +70,13 @@ pub struct SymbolAlreadyDefined { #[derive(Diagnostic)] #[diag(monomorphize_couldnt_dump_mono_stats)] -pub struct CouldntDumpMonoStats { +pub(crate) struct CouldntDumpMonoStats { pub error: String, } #[derive(Diagnostic)] #[diag(monomorphize_encountered_error_while_instantiating)] -pub struct EncounteredErrorWhileInstantiating { +pub(crate) struct EncounteredErrorWhileInstantiating { #[primary_span] pub span: Span, pub formatted_item: String, @@ -85,10 +85,10 @@ pub struct EncounteredErrorWhileInstantiating { #[derive(Diagnostic)] #[diag(monomorphize_start_not_found)] #[help] -pub struct StartNotFound; +pub(crate) struct StartNotFound; #[derive(Diagnostic)] #[diag(monomorphize_unknown_cgu_collection_mode)] -pub struct UnknownCguCollectionMode<'a> { +pub(crate) struct UnknownCguCollectionMode<'a> { pub mode: &'a str, } diff --git a/compiler/rustc_monomorphize/src/lib.rs b/compiler/rustc_monomorphize/src/lib.rs index d6b0f9c4d288f..b22e8e30465ea 100644 --- a/compiler/rustc_monomorphize/src/lib.rs +++ b/compiler/rustc_monomorphize/src/lib.rs @@ -1,5 +1,6 @@ // tidy-alphabetical-start #![feature(array_windows)] +#![warn(unreachable_pub)] // tidy-alphabetical-end use rustc_hir::lang_items::LangItem; diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 2f0088fb34ffd..0d295b8f280f5 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -1300,7 +1300,7 @@ fn dump_mono_items_stats<'tcx>( Ok(()) } -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { providers.collect_and_partition_mono_items = collect_and_partition_mono_items; providers.is_codegened_item = |tcx, def_id| { diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index b59c7bcffa9c7..c65ad9fa67e53 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -19,7 +19,7 @@ use tracing::{debug, instrument}; use crate::errors::UnusedGenericParamsHint; /// Provide implementations of queries relating to polymorphization analysis. -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { providers.unused_generic_params = unused_generic_params; } From 46ea798a94a9b5924518d64435e884f9d729b456 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 15:10:38 +1000 Subject: [PATCH 07/15] Add `warn(unreachable_pub)` to `rustc_next_trait_solver`. --- compiler/rustc_next_trait_solver/src/lib.rs | 4 ++ .../src/solve/eval_ctxt/mod.rs | 6 +-- .../src/solve/inspect/build.rs | 49 +++++++++++-------- .../src/solve/normalizes_to/opaque_types.rs | 4 +- 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_next_trait_solver/src/lib.rs b/compiler/rustc_next_trait_solver/src/lib.rs index 0a5b427805865..ea244b5107ad6 100644 --- a/compiler/rustc_next_trait_solver/src/lib.rs +++ b/compiler/rustc_next_trait_solver/src/lib.rs @@ -4,6 +4,10 @@ //! but were uplifted in the process of making the new trait solver generic. //! So if you got to this crate from the old solver, it's totally normal. +// tidy-alphabetical-start +#![warn(unreachable_pub)] +// tidy-alphabetical-end + pub mod canonicalizer; pub mod coherence; pub mod delegate; diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index e328284c0010f..3f2f34d3255f7 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -92,7 +92,7 @@ where #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))] // FIXME: This can be made crate-private once `EvalCtxt` also lives in this crate. -pub struct NestedGoals { +struct NestedGoals { /// These normalizes-to goals are treated specially during the evaluation /// loop. In each iteration we take the RHS of the projection, replace it with /// a fresh inference variable, and only after evaluating that goal do we @@ -109,11 +109,11 @@ pub struct NestedGoals { } impl NestedGoals { - pub fn new() -> Self { + fn new() -> Self { Self { normalizes_to_goals: Vec::new(), goals: Vec::new() } } - pub fn is_empty(&self) -> bool { + fn is_empty(&self) -> bool { self.normalizes_to_goals.is_empty() && self.goals.is_empty() } } diff --git a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs index 86fb036cd3df8..742d45de7d3de 100644 --- a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs +++ b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs @@ -222,13 +222,13 @@ impl, I: Interner> ProofTreeBuilder { self.state.as_deref_mut() } - pub fn take_and_enter_probe(&mut self) -> ProofTreeBuilder { + pub(crate) fn take_and_enter_probe(&mut self) -> ProofTreeBuilder { let mut nested = ProofTreeBuilder { state: self.state.take(), _infcx: PhantomData }; nested.enter_probe(); nested } - pub fn finalize(self) -> Option> { + pub(crate) fn finalize(self) -> Option> { match *self.state? { DebugSolver::GoalEvaluation(wip_goal_evaluation) => { Some(wip_goal_evaluation.finalize()) @@ -237,22 +237,22 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn new_maybe_root(generate_proof_tree: GenerateProofTree) -> ProofTreeBuilder { + pub(crate) fn new_maybe_root(generate_proof_tree: GenerateProofTree) -> ProofTreeBuilder { match generate_proof_tree { GenerateProofTree::No => ProofTreeBuilder::new_noop(), GenerateProofTree::Yes => ProofTreeBuilder::new_root(), } } - pub fn new_root() -> ProofTreeBuilder { + fn new_root() -> ProofTreeBuilder { ProofTreeBuilder::new(DebugSolver::Root) } - pub fn new_noop() -> ProofTreeBuilder { + fn new_noop() -> ProofTreeBuilder { ProofTreeBuilder { state: None, _infcx: PhantomData } } - pub fn is_noop(&self) -> bool { + pub(crate) fn is_noop(&self) -> bool { self.state.is_none() } @@ -272,7 +272,7 @@ impl, I: Interner> ProofTreeBuilder { }) } - pub fn new_canonical_goal_evaluation( + pub(crate) fn new_canonical_goal_evaluation( &mut self, goal: CanonicalInput, ) -> ProofTreeBuilder { @@ -284,7 +284,10 @@ impl, I: Interner> ProofTreeBuilder { }) } - pub fn canonical_goal_evaluation(&mut self, canonical_goal_evaluation: ProofTreeBuilder) { + pub(crate) fn canonical_goal_evaluation( + &mut self, + canonical_goal_evaluation: ProofTreeBuilder, + ) { if let Some(this) = self.as_mut() { match (this, *canonical_goal_evaluation.state.unwrap()) { ( @@ -299,7 +302,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn canonical_goal_evaluation_overflow(&mut self) { + pub(crate) fn canonical_goal_evaluation_overflow(&mut self) { if let Some(this) = self.as_mut() { match this { DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => { @@ -310,7 +313,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn goal_evaluation(&mut self, goal_evaluation: ProofTreeBuilder) { + pub(crate) fn goal_evaluation(&mut self, goal_evaluation: ProofTreeBuilder) { if let Some(this) = self.as_mut() { match this { DebugSolver::Root => *this = *goal_evaluation.state.unwrap(), @@ -322,7 +325,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn new_goal_evaluation_step( + pub(crate) fn new_goal_evaluation_step( &mut self, var_values: ty::CanonicalVarValues, instantiated_goal: QueryInput, @@ -340,7 +343,7 @@ impl, I: Interner> ProofTreeBuilder { }) } - pub fn goal_evaluation_step(&mut self, goal_evaluation_step: ProofTreeBuilder) { + pub(crate) fn goal_evaluation_step(&mut self, goal_evaluation_step: ProofTreeBuilder) { if let Some(this) = self.as_mut() { match (this, *goal_evaluation_step.state.unwrap()) { ( @@ -354,7 +357,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn add_var_value>(&mut self, arg: T) { + pub(crate) fn add_var_value>(&mut self, arg: T) { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { @@ -364,7 +367,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn enter_probe(&mut self) { + fn enter_probe(&mut self) { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { @@ -381,7 +384,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn probe_kind(&mut self, probe_kind: inspect::ProbeKind) { + pub(crate) fn probe_kind(&mut self, probe_kind: inspect::ProbeKind) { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { @@ -392,7 +395,11 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn probe_final_state(&mut self, delegate: &D, max_input_universe: ty::UniverseIndex) { + pub(crate) fn probe_final_state( + &mut self, + delegate: &D, + max_input_universe: ty::UniverseIndex, + ) { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { @@ -409,7 +416,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn add_normalizes_to_goal( + pub(crate) fn add_normalizes_to_goal( &mut self, delegate: &D, max_input_universe: ty::UniverseIndex, @@ -423,7 +430,7 @@ impl, I: Interner> ProofTreeBuilder { ); } - pub fn add_goal( + pub(crate) fn add_goal( &mut self, delegate: &D, max_input_universe: ty::UniverseIndex, @@ -469,7 +476,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn make_canonical_response(&mut self, shallow_certainty: Certainty) { + pub(crate) fn make_canonical_response(&mut self, shallow_certainty: Certainty) { match self.as_mut() { Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { state @@ -482,7 +489,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn finish_probe(mut self) -> ProofTreeBuilder { + pub(crate) fn finish_probe(mut self) -> ProofTreeBuilder { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { @@ -497,7 +504,7 @@ impl, I: Interner> ProofTreeBuilder { self } - pub fn query_result(&mut self, result: QueryResult) { + pub(crate) fn query_result(&mut self, result: QueryResult) { if let Some(this) = self.as_mut() { match this { DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => { diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs index 120f96d24bda3..6a0703c531323 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs @@ -97,7 +97,7 @@ where /// Checks whether each generic argument is simply a unique generic placeholder. /// /// FIXME: Interner argument is needed to constrain the `I` parameter. -pub fn uses_unique_placeholders_ignoring_regions( +fn uses_unique_placeholders_ignoring_regions( _cx: I, args: I::GenericArgs, ) -> Result<(), NotUniqueParam> { @@ -130,7 +130,7 @@ pub fn uses_unique_placeholders_ignoring_regions( } // FIXME: This should check for dupes and non-params first, then infer vars. -pub enum NotUniqueParam { +enum NotUniqueParam { DuplicateParam(I::GenericArg), NotParam(I::GenericArg), } From cac04a1cb97f1339ab866051f7048786298e66b7 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 15:13:12 +1000 Subject: [PATCH 08/15] Add `warn(unreachable_pub)` to `rustc_parser`. --- compiler/rustc_parse/src/errors.rs | 70 +++++++++++++++--------------- compiler/rustc_parse/src/lib.rs | 1 + 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index abaff7d9c19eb..da1103a4fe5dc 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -260,7 +260,7 @@ pub(crate) struct NotAsNegationOperator { } #[derive(Subdiagnostic)] -pub enum NotAsNegationOperatorSub { +pub(crate) enum NotAsNegationOperatorSub { #[suggestion( parse_unexpected_token_after_not_default, style = "verbose", @@ -424,7 +424,7 @@ pub(crate) enum IfExpressionMissingThenBlockSub { #[derive(Diagnostic)] #[diag(parse_ternary_operator)] #[help] -pub struct TernaryOperator { +pub(crate) struct TernaryOperator { #[primary_span] pub span: Span, } @@ -1088,7 +1088,7 @@ pub(crate) enum ExpectedIdentifierFound { } impl ExpectedIdentifierFound { - pub fn new(token_descr: Option, span: Span) -> Self { + pub(crate) fn new(token_descr: Option, span: Span) -> Self { (match token_descr { Some(TokenDescription::ReservedIdentifier) => { ExpectedIdentifierFound::ReservedIdentifier @@ -1659,7 +1659,7 @@ pub(crate) struct SelfArgumentPointer { #[derive(Diagnostic)] #[diag(parse_unexpected_token_after_dot)] -pub struct UnexpectedTokenAfterDot<'a> { +pub(crate) struct UnexpectedTokenAfterDot<'a> { #[primary_span] pub span: Span, pub actual: Cow<'a, str>, @@ -1928,7 +1928,7 @@ pub(crate) enum UnexpectedTokenAfterStructName { } impl UnexpectedTokenAfterStructName { - pub fn new(span: Span, token: Token) -> Self { + pub(crate) fn new(span: Span, token: Token) -> Self { match TokenDescription::from_token(&token) { Some(TokenDescription::ReservedIdentifier) => Self::ReservedIdentifier { span, token }, Some(TokenDescription::Keyword) => Self::Keyword { span, token }, @@ -2006,7 +2006,7 @@ pub(crate) enum TopLevelOrPatternNotAllowed { #[derive(Diagnostic)] #[diag(parse_cannot_be_raw_ident)] -pub struct CannotBeRawIdent { +pub(crate) struct CannotBeRawIdent { #[primary_span] pub span: Span, pub ident: Symbol, @@ -2014,14 +2014,14 @@ pub struct CannotBeRawIdent { #[derive(Diagnostic)] #[diag(parse_keyword_lifetime)] -pub struct KeywordLifetime { +pub(crate) struct KeywordLifetime { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(parse_invalid_label)] -pub struct InvalidLabel { +pub(crate) struct InvalidLabel { #[primary_span] pub span: Span, pub name: Symbol, @@ -2029,7 +2029,7 @@ pub struct InvalidLabel { #[derive(Diagnostic)] #[diag(parse_cr_doc_comment)] -pub struct CrDocComment { +pub(crate) struct CrDocComment { #[primary_span] pub span: Span, pub block: bool, @@ -2037,14 +2037,14 @@ pub struct CrDocComment { #[derive(Diagnostic)] #[diag(parse_no_digits_literal, code = E0768)] -pub struct NoDigitsLiteral { +pub(crate) struct NoDigitsLiteral { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(parse_invalid_digit_literal)] -pub struct InvalidDigitLiteral { +pub(crate) struct InvalidDigitLiteral { #[primary_span] pub span: Span, pub base: u32, @@ -2052,14 +2052,14 @@ pub struct InvalidDigitLiteral { #[derive(Diagnostic)] #[diag(parse_empty_exponent_float)] -pub struct EmptyExponentFloat { +pub(crate) struct EmptyExponentFloat { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(parse_float_literal_unsupported_base)] -pub struct FloatLiteralUnsupportedBase { +pub(crate) struct FloatLiteralUnsupportedBase { #[primary_span] pub span: Span, pub base: &'static str, @@ -2068,7 +2068,7 @@ pub struct FloatLiteralUnsupportedBase { #[derive(Diagnostic)] #[diag(parse_unknown_prefix)] #[note] -pub struct UnknownPrefix<'a> { +pub(crate) struct UnknownPrefix<'a> { #[primary_span] #[label] pub span: Span, @@ -2079,12 +2079,12 @@ pub struct UnknownPrefix<'a> { #[derive(Subdiagnostic)] #[note(parse_macro_expands_to_adt_field)] -pub struct MacroExpandsToAdtField<'a> { +pub(crate) struct MacroExpandsToAdtField<'a> { pub adt_ty: &'a str, } #[derive(Subdiagnostic)] -pub enum UnknownPrefixSugg { +pub(crate) enum UnknownPrefixSugg { #[suggestion( parse_suggestion_br, code = "br", @@ -2114,7 +2114,7 @@ pub enum UnknownPrefixSugg { #[derive(Diagnostic)] #[diag(parse_too_many_hashes)] -pub struct TooManyHashes { +pub(crate) struct TooManyHashes { #[primary_span] pub span: Span, pub num: u32, @@ -2122,7 +2122,7 @@ pub struct TooManyHashes { #[derive(Diagnostic)] #[diag(parse_unknown_start_of_token)] -pub struct UnknownTokenStart { +pub(crate) struct UnknownTokenStart { #[primary_span] pub span: Span, pub escaped: String, @@ -2135,7 +2135,7 @@ pub struct UnknownTokenStart { } #[derive(Subdiagnostic)] -pub enum TokenSubstitution { +pub(crate) enum TokenSubstitution { #[suggestion( parse_sugg_quotes, code = "{suggestion}", @@ -2168,16 +2168,16 @@ pub enum TokenSubstitution { #[derive(Subdiagnostic)] #[note(parse_note_repeats)] -pub struct UnknownTokenRepeat { +pub(crate) struct UnknownTokenRepeat { pub repeats: usize, } #[derive(Subdiagnostic)] #[help(parse_help_null)] -pub struct UnknownTokenNull; +pub(crate) struct UnknownTokenNull; #[derive(Diagnostic)] -pub enum UnescapeError { +pub(crate) enum UnescapeError { #[diag(parse_invalid_unicode_escape)] #[help] InvalidUnicodeEscape { @@ -2322,7 +2322,7 @@ pub enum UnescapeError { } #[derive(Subdiagnostic)] -pub enum MoreThanOneCharSugg { +pub(crate) enum MoreThanOneCharSugg { #[suggestion( parse_consider_normalized, code = "{normalized}", @@ -2370,7 +2370,7 @@ pub enum MoreThanOneCharSugg { } #[derive(Subdiagnostic)] -pub enum MoreThanOneCharNote { +pub(crate) enum MoreThanOneCharNote { #[note(parse_followed_by)] AllCombining { #[primary_span] @@ -2388,7 +2388,7 @@ pub enum MoreThanOneCharNote { } #[derive(Subdiagnostic)] -pub enum NoBraceUnicodeSub { +pub(crate) enum NoBraceUnicodeSub { #[suggestion( parse_use_braces, code = "{suggestion}", @@ -2703,7 +2703,7 @@ pub(crate) struct InvalidDynKeyword { } #[derive(Subdiagnostic)] -pub enum HelpUseLatestEdition { +pub(crate) enum HelpUseLatestEdition { #[help(parse_help_set_edition_cargo)] #[note(parse_note_edition_guide)] Cargo { edition: Edition }, @@ -2713,7 +2713,7 @@ pub enum HelpUseLatestEdition { } impl HelpUseLatestEdition { - pub fn new() -> Self { + pub(crate) fn new() -> Self { let edition = LATEST_STABLE_EDITION; if rustc_session::utils::was_invoked_from_cargo() { Self::Cargo { edition } @@ -2725,7 +2725,7 @@ impl HelpUseLatestEdition { #[derive(Diagnostic)] #[diag(parse_box_syntax_removed)] -pub struct BoxSyntaxRemoved { +pub(crate) struct BoxSyntaxRemoved { #[primary_span] pub span: Span, #[subdiagnostic] @@ -2738,7 +2738,7 @@ pub struct BoxSyntaxRemoved { applicability = "machine-applicable", style = "verbose" )] -pub struct AddBoxNew { +pub(crate) struct AddBoxNew { #[suggestion_part(code = "Box::new(")] pub box_kw_and_lo: Span, #[suggestion_part(code = ")")] @@ -3190,7 +3190,7 @@ pub(crate) struct DotDotRangeAttribute { #[derive(Diagnostic)] #[diag(parse_invalid_attr_unsafe)] #[note] -pub struct InvalidAttrUnsafe { +pub(crate) struct InvalidAttrUnsafe { #[primary_span] #[label] pub span: Span, @@ -3199,7 +3199,7 @@ pub struct InvalidAttrUnsafe { #[derive(Diagnostic)] #[diag(parse_unsafe_attr_outside_unsafe)] -pub struct UnsafeAttrOutsideUnsafe { +pub(crate) struct UnsafeAttrOutsideUnsafe { #[primary_span] #[label] pub span: Span, @@ -3212,7 +3212,7 @@ pub struct UnsafeAttrOutsideUnsafe { parse_unsafe_attr_outside_unsafe_suggestion, applicability = "machine-applicable" )] -pub struct UnsafeAttrOutsideUnsafeSuggestion { +pub(crate) struct UnsafeAttrOutsideUnsafeSuggestion { #[suggestion_part(code = "unsafe(")] pub left: Span, #[suggestion_part(code = ")")] @@ -3221,7 +3221,7 @@ pub struct UnsafeAttrOutsideUnsafeSuggestion { #[derive(Diagnostic)] #[diag(parse_binder_before_modifiers)] -pub struct BinderBeforeModifiers { +pub(crate) struct BinderBeforeModifiers { #[primary_span] pub binder_span: Span, #[label] @@ -3230,7 +3230,7 @@ pub struct BinderBeforeModifiers { #[derive(Diagnostic)] #[diag(parse_binder_and_polarity)] -pub struct BinderAndPolarity { +pub(crate) struct BinderAndPolarity { #[primary_span] pub polarity_span: Span, #[label] @@ -3240,7 +3240,7 @@ pub struct BinderAndPolarity { #[derive(Diagnostic)] #[diag(parse_modifiers_and_polarity)] -pub struct PolarityAndModifiers { +pub(crate) struct PolarityAndModifiers { #[primary_span] pub polarity_span: Span, #[label] diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 370792714936a..788bb732ef722 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -11,6 +11,7 @@ #![feature(if_let_guard)] #![feature(iter_intersperse)] #![feature(let_chains)] +#![warn(unreachable_pub)] // tidy-alphabetical-end use std::path::Path; From 76bd802403ec5aa3e478fc628ad71529fc26417a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 15:14:32 +1000 Subject: [PATCH 09/15] Add `warn(unreachable_pub)` to `rustc_parse_format`. --- compiler/rustc_parse_format/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_parse_format/src/lib.rs b/compiler/rustc_parse_format/src/lib.rs index cb758150789b0..51084ef4441d7 100644 --- a/compiler/rustc_parse_format/src/lib.rs +++ b/compiler/rustc_parse_format/src/lib.rs @@ -13,6 +13,7 @@ html_playground_url = "https://play.rust-lang.org/", test(attr(deny(warnings))) )] +#![warn(unreachable_pub)] // tidy-alphabetical-end use std::{iter, str, string}; From f77821203f73f3f71a4e92afddf17c5da8e89d9b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 15:17:14 +1000 Subject: [PATCH 10/15] Add `warn(unreachable_pub)` to `rustc_passes`. --- .../rustc_passes/src/debugger_visualizer.rs | 2 +- compiler/rustc_passes/src/diagnostic_items.rs | 2 +- compiler/rustc_passes/src/errors.rs | 366 +++++++++--------- compiler/rustc_passes/src/lang_items.rs | 2 +- compiler/rustc_passes/src/lib.rs | 1 + compiler/rustc_passes/src/lib_features.rs | 4 +- compiler/rustc_passes/src/liveness.rs | 2 +- compiler/rustc_passes/src/reachable.rs | 2 +- compiler/rustc_passes/src/upvars.rs | 2 +- compiler/rustc_passes/src/weak_lang_items.rs | 6 +- 10 files changed, 197 insertions(+), 192 deletions(-) diff --git a/compiler/rustc_passes/src/debugger_visualizer.rs b/compiler/rustc_passes/src/debugger_visualizer.rs index 5d871bacb1dae..fec149c8c4324 100644 --- a/compiler/rustc_passes/src/debugger_visualizer.rs +++ b/compiler/rustc_passes/src/debugger_visualizer.rs @@ -95,6 +95,6 @@ fn debugger_visualizers(tcx: TyCtxt<'_>, _: LocalCrate) -> Vec, (): ()) -> DiagnosticItems { items } -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { providers.diagnostic_items = diagnostic_items; providers.all_diagnostic_items = all_diagnostic_items; } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 32db0823cf786..1e9ab7af9becc 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -18,41 +18,41 @@ use crate::lang_items::Duplicate; #[derive(LintDiagnostic)] #[diag(passes_incorrect_do_not_recommend_location)] -pub struct IncorrectDoNotRecommendLocation; +pub(crate) struct IncorrectDoNotRecommendLocation; #[derive(LintDiagnostic)] #[diag(passes_outer_crate_level_attr)] -pub struct OuterCrateLevelAttr; +pub(crate) struct OuterCrateLevelAttr; #[derive(LintDiagnostic)] #[diag(passes_inner_crate_level_attr)] -pub struct InnerCrateLevelAttr; +pub(crate) struct InnerCrateLevelAttr; #[derive(LintDiagnostic)] #[diag(passes_ignored_attr_with_macro)] -pub struct IgnoredAttrWithMacro<'a> { +pub(crate) struct IgnoredAttrWithMacro<'a> { pub sym: &'a str, } #[derive(LintDiagnostic)] #[diag(passes_ignored_attr)] -pub struct IgnoredAttr<'a> { +pub(crate) struct IgnoredAttr<'a> { pub sym: &'a str, } #[derive(LintDiagnostic)] #[diag(passes_inline_ignored_function_prototype)] -pub struct IgnoredInlineAttrFnProto; +pub(crate) struct IgnoredInlineAttrFnProto; #[derive(LintDiagnostic)] #[diag(passes_inline_ignored_constants)] #[warning] #[note] -pub struct IgnoredInlineAttrConstants; +pub(crate) struct IgnoredInlineAttrConstants; #[derive(Diagnostic)] #[diag(passes_inline_not_fn_or_closure, code = E0518)] -pub struct InlineNotFnOrClosure { +pub(crate) struct InlineNotFnOrClosure { #[primary_span] pub attr_span: Span, #[label] @@ -61,7 +61,7 @@ pub struct InlineNotFnOrClosure { #[derive(Diagnostic)] #[diag(passes_coverage_not_fn_or_closure, code = E0788)] -pub struct CoverageNotFnOrClosure { +pub(crate) struct CoverageNotFnOrClosure { #[primary_span] pub attr_span: Span, #[label] @@ -70,11 +70,11 @@ pub struct CoverageNotFnOrClosure { #[derive(LintDiagnostic)] #[diag(passes_optimize_not_fn_or_closure)] -pub struct OptimizeNotFnOrClosure; +pub(crate) struct OptimizeNotFnOrClosure; #[derive(Diagnostic)] #[diag(passes_should_be_applied_to_fn)] -pub struct AttrShouldBeAppliedToFn { +pub(crate) struct AttrShouldBeAppliedToFn { #[primary_span] pub attr_span: Span, #[label] @@ -84,7 +84,7 @@ pub struct AttrShouldBeAppliedToFn { #[derive(Diagnostic)] #[diag(passes_should_be_applied_to_fn_or_unit_struct)] -pub struct AttrShouldBeAppliedToFnOrUnitStruct { +pub(crate) struct AttrShouldBeAppliedToFnOrUnitStruct { #[primary_span] pub attr_span: Span, #[label] @@ -93,7 +93,7 @@ pub struct AttrShouldBeAppliedToFnOrUnitStruct { #[derive(Diagnostic)] #[diag(passes_should_be_applied_to_fn, code = E0739)] -pub struct TrackedCallerWrongLocation { +pub(crate) struct TrackedCallerWrongLocation { #[primary_span] pub attr_span: Span, #[label] @@ -103,7 +103,7 @@ pub struct TrackedCallerWrongLocation { #[derive(Diagnostic)] #[diag(passes_should_be_applied_to_struct_enum, code = E0701)] -pub struct NonExhaustiveWrongLocation { +pub(crate) struct NonExhaustiveWrongLocation { #[primary_span] pub attr_span: Span, #[label] @@ -112,7 +112,7 @@ pub struct NonExhaustiveWrongLocation { #[derive(Diagnostic)] #[diag(passes_should_be_applied_to_trait)] -pub struct AttrShouldBeAppliedToTrait { +pub(crate) struct AttrShouldBeAppliedToTrait { #[primary_span] pub attr_span: Span, #[label] @@ -121,11 +121,11 @@ pub struct AttrShouldBeAppliedToTrait { #[derive(LintDiagnostic)] #[diag(passes_target_feature_on_statement)] -pub struct TargetFeatureOnStatement; +pub(crate) struct TargetFeatureOnStatement; #[derive(Diagnostic)] #[diag(passes_should_be_applied_to_static)] -pub struct AttrShouldBeAppliedToStatic { +pub(crate) struct AttrShouldBeAppliedToStatic { #[primary_span] pub attr_span: Span, #[label] @@ -134,7 +134,7 @@ pub struct AttrShouldBeAppliedToStatic { #[derive(Diagnostic)] #[diag(passes_doc_expect_str)] -pub struct DocExpectStr<'a> { +pub(crate) struct DocExpectStr<'a> { #[primary_span] pub attr_span: Span, pub attr_name: &'a str, @@ -142,7 +142,7 @@ pub struct DocExpectStr<'a> { #[derive(Diagnostic)] #[diag(passes_doc_alias_empty)] -pub struct DocAliasEmpty<'a> { +pub(crate) struct DocAliasEmpty<'a> { #[primary_span] pub span: Span, pub attr_str: &'a str, @@ -150,7 +150,7 @@ pub struct DocAliasEmpty<'a> { #[derive(Diagnostic)] #[diag(passes_doc_alias_bad_char)] -pub struct DocAliasBadChar<'a> { +pub(crate) struct DocAliasBadChar<'a> { #[primary_span] pub span: Span, pub attr_str: &'a str, @@ -159,7 +159,7 @@ pub struct DocAliasBadChar<'a> { #[derive(Diagnostic)] #[diag(passes_doc_alias_start_end)] -pub struct DocAliasStartEnd<'a> { +pub(crate) struct DocAliasStartEnd<'a> { #[primary_span] pub span: Span, pub attr_str: &'a str, @@ -167,7 +167,7 @@ pub struct DocAliasStartEnd<'a> { #[derive(Diagnostic)] #[diag(passes_doc_alias_bad_location)] -pub struct DocAliasBadLocation<'a> { +pub(crate) struct DocAliasBadLocation<'a> { #[primary_span] pub span: Span, pub attr_str: &'a str, @@ -176,7 +176,7 @@ pub struct DocAliasBadLocation<'a> { #[derive(Diagnostic)] #[diag(passes_doc_alias_not_an_alias)] -pub struct DocAliasNotAnAlias<'a> { +pub(crate) struct DocAliasNotAnAlias<'a> { #[primary_span] pub span: Span, pub attr_str: &'a str, @@ -184,42 +184,42 @@ pub struct DocAliasNotAnAlias<'a> { #[derive(LintDiagnostic)] #[diag(passes_doc_alias_duplicated)] -pub struct DocAliasDuplicated { +pub(crate) struct DocAliasDuplicated { #[label] pub first_defn: Span, } #[derive(Diagnostic)] #[diag(passes_doc_alias_not_string_literal)] -pub struct DocAliasNotStringLiteral { +pub(crate) struct DocAliasNotStringLiteral { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_doc_alias_malformed)] -pub struct DocAliasMalformed { +pub(crate) struct DocAliasMalformed { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_doc_keyword_empty_mod)] -pub struct DocKeywordEmptyMod { +pub(crate) struct DocKeywordEmptyMod { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_doc_keyword_not_mod)] -pub struct DocKeywordNotMod { +pub(crate) struct DocKeywordNotMod { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_doc_keyword_invalid_ident)] -pub struct DocKeywordInvalidIdent { +pub(crate) struct DocKeywordInvalidIdent { #[primary_span] pub span: Span, pub doc_keyword: Symbol, @@ -227,14 +227,14 @@ pub struct DocKeywordInvalidIdent { #[derive(Diagnostic)] #[diag(passes_doc_fake_variadic_not_valid)] -pub struct DocFakeVariadicNotValid { +pub(crate) struct DocFakeVariadicNotValid { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_doc_keyword_only_impl)] -pub struct DocKeywordOnlyImpl { +pub(crate) struct DocKeywordOnlyImpl { #[primary_span] pub span: Span, } @@ -242,7 +242,7 @@ pub struct DocKeywordOnlyImpl { #[derive(Diagnostic)] #[diag(passes_doc_inline_conflict)] #[help] -pub struct DocKeywordConflict { +pub(crate) struct DocKeywordConflict { #[primary_span] pub spans: MultiSpan, } @@ -250,7 +250,7 @@ pub struct DocKeywordConflict { #[derive(LintDiagnostic)] #[diag(passes_doc_inline_only_use)] #[note] -pub struct DocInlineOnlyUse { +pub(crate) struct DocInlineOnlyUse { #[label] pub attr_span: Span, #[label(passes_not_a_use_item_label)] @@ -260,7 +260,7 @@ pub struct DocInlineOnlyUse { #[derive(LintDiagnostic)] #[diag(passes_doc_masked_only_extern_crate)] #[note] -pub struct DocMaskedOnlyExternCrate { +pub(crate) struct DocMaskedOnlyExternCrate { #[label] pub attr_span: Span, #[label(passes_not_an_extern_crate_label)] @@ -269,7 +269,7 @@ pub struct DocMaskedOnlyExternCrate { #[derive(LintDiagnostic)] #[diag(passes_doc_masked_not_extern_crate_self)] -pub struct DocMaskedNotExternCrateSelf { +pub(crate) struct DocMaskedNotExternCrateSelf { #[label] pub attr_span: Span, #[label(passes_extern_crate_self_label)] @@ -278,7 +278,7 @@ pub struct DocMaskedNotExternCrateSelf { #[derive(Diagnostic)] #[diag(passes_doc_attr_not_crate_level)] -pub struct DocAttrNotCrateLevel<'a> { +pub(crate) struct DocAttrNotCrateLevel<'a> { #[primary_span] pub span: Span, pub attr_name: &'a str, @@ -286,25 +286,25 @@ pub struct DocAttrNotCrateLevel<'a> { #[derive(LintDiagnostic)] #[diag(passes_doc_test_unknown)] -pub struct DocTestUnknown { +pub(crate) struct DocTestUnknown { pub path: String, } #[derive(LintDiagnostic)] #[diag(passes_doc_test_literal)] -pub struct DocTestLiteral; +pub(crate) struct DocTestLiteral; #[derive(LintDiagnostic)] #[diag(passes_doc_test_takes_list)] -pub struct DocTestTakesList; +pub(crate) struct DocTestTakesList; #[derive(LintDiagnostic)] #[diag(passes_doc_cfg_hide_takes_list)] -pub struct DocCfgHideTakesList; +pub(crate) struct DocCfgHideTakesList; #[derive(LintDiagnostic)] #[diag(passes_doc_test_unknown_any)] -pub struct DocTestUnknownAny { +pub(crate) struct DocTestUnknownAny { pub path: String, } @@ -312,7 +312,7 @@ pub struct DocTestUnknownAny { #[diag(passes_doc_test_unknown_spotlight)] #[note] #[note(passes_no_op_note)] -pub struct DocTestUnknownSpotlight { +pub(crate) struct DocTestUnknownSpotlight { pub path: String, #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")] pub span: Span, @@ -320,7 +320,7 @@ pub struct DocTestUnknownSpotlight { #[derive(LintDiagnostic)] #[diag(passes_doc_test_unknown_include)] -pub struct DocTestUnknownInclude { +pub(crate) struct DocTestUnknownInclude { pub path: String, pub value: String, pub inner: &'static str, @@ -330,11 +330,11 @@ pub struct DocTestUnknownInclude { #[derive(LintDiagnostic)] #[diag(passes_doc_invalid)] -pub struct DocInvalid; +pub(crate) struct DocInvalid; #[derive(Diagnostic)] #[diag(passes_pass_by_value)] -pub struct PassByValue { +pub(crate) struct PassByValue { #[primary_span] pub attr_span: Span, #[label] @@ -343,7 +343,7 @@ pub struct PassByValue { #[derive(Diagnostic)] #[diag(passes_allow_incoherent_impl)] -pub struct AllowIncoherentImpl { +pub(crate) struct AllowIncoherentImpl { #[primary_span] pub attr_span: Span, #[label] @@ -352,7 +352,7 @@ pub struct AllowIncoherentImpl { #[derive(Diagnostic)] #[diag(passes_has_incoherent_inherent_impl)] -pub struct HasIncoherentInherentImpl { +pub(crate) struct HasIncoherentInherentImpl { #[primary_span] pub attr_span: Span, #[label] @@ -361,35 +361,35 @@ pub struct HasIncoherentInherentImpl { #[derive(Diagnostic)] #[diag(passes_both_ffi_const_and_pure, code = E0757)] -pub struct BothFfiConstAndPure { +pub(crate) struct BothFfiConstAndPure { #[primary_span] pub attr_span: Span, } #[derive(Diagnostic)] #[diag(passes_ffi_pure_invalid_target, code = E0755)] -pub struct FfiPureInvalidTarget { +pub(crate) struct FfiPureInvalidTarget { #[primary_span] pub attr_span: Span, } #[derive(Diagnostic)] #[diag(passes_ffi_const_invalid_target, code = E0756)] -pub struct FfiConstInvalidTarget { +pub(crate) struct FfiConstInvalidTarget { #[primary_span] pub attr_span: Span, } #[derive(LintDiagnostic)] #[diag(passes_must_use_no_effect)] -pub struct MustUseNoEffect { +pub(crate) struct MustUseNoEffect { pub article: &'static str, pub target: rustc_hir::Target, } #[derive(Diagnostic)] #[diag(passes_must_not_suspend)] -pub struct MustNotSuspend { +pub(crate) struct MustNotSuspend { #[primary_span] pub attr_span: Span, #[label] @@ -399,7 +399,7 @@ pub struct MustNotSuspend { #[derive(LintDiagnostic)] #[diag(passes_cold)] #[warning] -pub struct Cold { +pub(crate) struct Cold { #[label] pub span: Span, pub on_crate: bool, @@ -408,7 +408,7 @@ pub struct Cold { #[derive(LintDiagnostic)] #[diag(passes_link)] #[warning] -pub struct Link { +pub(crate) struct Link { #[label] pub span: Option, } @@ -416,7 +416,7 @@ pub struct Link { #[derive(LintDiagnostic)] #[diag(passes_link_name)] #[warning] -pub struct LinkName<'a> { +pub(crate) struct LinkName<'a> { #[help] pub attr_span: Option, #[label] @@ -426,7 +426,7 @@ pub struct LinkName<'a> { #[derive(Diagnostic)] #[diag(passes_no_link)] -pub struct NoLink { +pub(crate) struct NoLink { #[primary_span] pub attr_span: Span, #[label] @@ -435,7 +435,7 @@ pub struct NoLink { #[derive(Diagnostic)] #[diag(passes_export_name)] -pub struct ExportName { +pub(crate) struct ExportName { #[primary_span] pub attr_span: Span, #[label] @@ -444,7 +444,7 @@ pub struct ExportName { #[derive(Diagnostic)] #[diag(passes_rustc_layout_scalar_valid_range_not_struct)] -pub struct RustcLayoutScalarValidRangeNotStruct { +pub(crate) struct RustcLayoutScalarValidRangeNotStruct { #[primary_span] pub attr_span: Span, #[label] @@ -453,14 +453,14 @@ pub struct RustcLayoutScalarValidRangeNotStruct { #[derive(Diagnostic)] #[diag(passes_rustc_layout_scalar_valid_range_arg)] -pub struct RustcLayoutScalarValidRangeArg { +pub(crate) struct RustcLayoutScalarValidRangeArg { #[primary_span] pub attr_span: Span, } #[derive(Diagnostic)] #[diag(passes_rustc_legacy_const_generics_only)] -pub struct RustcLegacyConstGenericsOnly { +pub(crate) struct RustcLegacyConstGenericsOnly { #[primary_span] pub attr_span: Span, #[label] @@ -469,7 +469,7 @@ pub struct RustcLegacyConstGenericsOnly { #[derive(Diagnostic)] #[diag(passes_rustc_legacy_const_generics_index)] -pub struct RustcLegacyConstGenericsIndex { +pub(crate) struct RustcLegacyConstGenericsIndex { #[primary_span] pub attr_span: Span, #[label] @@ -478,7 +478,7 @@ pub struct RustcLegacyConstGenericsIndex { #[derive(Diagnostic)] #[diag(passes_rustc_legacy_const_generics_index_exceed)] -pub struct RustcLegacyConstGenericsIndexExceed { +pub(crate) struct RustcLegacyConstGenericsIndexExceed { #[primary_span] #[label] pub span: Span, @@ -487,14 +487,14 @@ pub struct RustcLegacyConstGenericsIndexExceed { #[derive(Diagnostic)] #[diag(passes_rustc_legacy_const_generics_index_negative)] -pub struct RustcLegacyConstGenericsIndexNegative { +pub(crate) struct RustcLegacyConstGenericsIndexNegative { #[primary_span] pub invalid_args: Vec, } #[derive(Diagnostic)] #[diag(passes_rustc_dirty_clean)] -pub struct RustcDirtyClean { +pub(crate) struct RustcDirtyClean { #[primary_span] pub span: Span, } @@ -502,7 +502,7 @@ pub struct RustcDirtyClean { #[derive(LintDiagnostic)] #[diag(passes_link_section)] #[warning] -pub struct LinkSection { +pub(crate) struct LinkSection { #[label] pub span: Span, } @@ -511,7 +511,7 @@ pub struct LinkSection { #[diag(passes_no_mangle_foreign)] #[warning] #[note] -pub struct NoMangleForeign { +pub(crate) struct NoMangleForeign { #[label] pub span: Span, #[suggestion(code = "", applicability = "machine-applicable")] @@ -522,32 +522,32 @@ pub struct NoMangleForeign { #[derive(LintDiagnostic)] #[diag(passes_no_mangle)] #[warning] -pub struct NoMangle { +pub(crate) struct NoMangle { #[label] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_repr_ident, code = E0565)] -pub struct ReprIdent { +pub(crate) struct ReprIdent { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_repr_conflicting, code = E0566)] -pub struct ReprConflicting { +pub(crate) struct ReprConflicting { #[primary_span] pub hint_spans: Vec, } #[derive(LintDiagnostic)] #[diag(passes_repr_conflicting, code = E0566)] -pub struct ReprConflictingLint; +pub(crate) struct ReprConflictingLint; #[derive(Diagnostic)] #[diag(passes_used_static)] -pub struct UsedStatic { +pub(crate) struct UsedStatic { #[primary_span] pub attr_span: Span, #[label] @@ -557,14 +557,14 @@ pub struct UsedStatic { #[derive(Diagnostic)] #[diag(passes_used_compiler_linker)] -pub struct UsedCompilerLinker { +pub(crate) struct UsedCompilerLinker { #[primary_span] pub spans: Vec, } #[derive(Diagnostic)] #[diag(passes_allow_internal_unstable)] -pub struct AllowInternalUnstable { +pub(crate) struct AllowInternalUnstable { #[primary_span] pub attr_span: Span, #[label] @@ -573,7 +573,7 @@ pub struct AllowInternalUnstable { #[derive(Diagnostic)] #[diag(passes_debug_visualizer_placement)] -pub struct DebugVisualizerPlacement { +pub(crate) struct DebugVisualizerPlacement { #[primary_span] pub span: Span, } @@ -583,14 +583,14 @@ pub struct DebugVisualizerPlacement { #[note(passes_note_1)] #[note(passes_note_2)] #[note(passes_note_3)] -pub struct DebugVisualizerInvalid { +pub(crate) struct DebugVisualizerInvalid { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_debug_visualizer_unreadable)] -pub struct DebugVisualizerUnreadable<'a> { +pub(crate) struct DebugVisualizerUnreadable<'a> { #[primary_span] pub span: Span, pub file: &'a Path, @@ -599,7 +599,7 @@ pub struct DebugVisualizerUnreadable<'a> { #[derive(Diagnostic)] #[diag(passes_rustc_allow_const_fn_unstable)] -pub struct RustcAllowConstFnUnstable { +pub(crate) struct RustcAllowConstFnUnstable { #[primary_span] pub attr_span: Span, #[label] @@ -608,7 +608,7 @@ pub struct RustcAllowConstFnUnstable { #[derive(Diagnostic)] #[diag(passes_rustc_safe_intrinsic)] -pub struct RustcSafeIntrinsic { +pub(crate) struct RustcSafeIntrinsic { #[primary_span] pub attr_span: Span, #[label] @@ -617,7 +617,7 @@ pub struct RustcSafeIntrinsic { #[derive(Diagnostic)] #[diag(passes_rustc_std_internal_symbol)] -pub struct RustcStdInternalSymbol { +pub(crate) struct RustcStdInternalSymbol { #[primary_span] pub attr_span: Span, #[label] @@ -626,7 +626,7 @@ pub struct RustcStdInternalSymbol { #[derive(Diagnostic)] #[diag(passes_rustc_pub_transparent)] -pub struct RustcPubTransparent { +pub(crate) struct RustcPubTransparent { #[primary_span] pub attr_span: Span, #[label] @@ -635,28 +635,28 @@ pub struct RustcPubTransparent { #[derive(Diagnostic)] #[diag(passes_link_ordinal)] -pub struct LinkOrdinal { +pub(crate) struct LinkOrdinal { #[primary_span] pub attr_span: Span, } #[derive(Diagnostic)] #[diag(passes_confusables)] -pub struct Confusables { +pub(crate) struct Confusables { #[primary_span] pub attr_span: Span, } #[derive(Diagnostic)] #[diag(passes_coroutine_on_non_closure)] -pub struct CoroutineOnNonClosure { +pub(crate) struct CoroutineOnNonClosure { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_linkage)] -pub struct Linkage { +pub(crate) struct Linkage { #[primary_span] pub attr_span: Span, #[label] @@ -690,23 +690,23 @@ pub(crate) struct IncorrectMetaItemSuggestion { #[derive(Diagnostic)] #[diag(passes_stability_promotable)] -pub struct StabilityPromotable { +pub(crate) struct StabilityPromotable { #[primary_span] pub attr_span: Span, } #[derive(LintDiagnostic)] #[diag(passes_deprecated)] -pub struct Deprecated; +pub(crate) struct Deprecated; #[derive(LintDiagnostic)] #[diag(passes_macro_use)] -pub struct MacroUse { +pub(crate) struct MacroUse { pub name: Symbol, } #[derive(LintDiagnostic)] -pub enum MacroExport { +pub(crate) enum MacroExport { #[diag(passes_macro_export)] Normal, @@ -722,7 +722,7 @@ pub enum MacroExport { } #[derive(Subdiagnostic)] -pub enum UnusedNote { +pub(crate) enum UnusedNote { #[note(passes_unused_empty_lints_note)] EmptyList { name: Symbol }, #[note(passes_unused_no_lints_note)] @@ -733,7 +733,7 @@ pub enum UnusedNote { #[derive(LintDiagnostic)] #[diag(passes_unused)] -pub struct Unused { +pub(crate) struct Unused { #[suggestion(code = "", applicability = "machine-applicable")] pub attr_span: Span, #[subdiagnostic] @@ -742,7 +742,7 @@ pub struct Unused { #[derive(Diagnostic)] #[diag(passes_non_exported_macro_invalid_attrs, code = E0518)] -pub struct NonExportedMacroInvalidAttrs { +pub(crate) struct NonExportedMacroInvalidAttrs { #[primary_span] #[label] pub attr_span: Span, @@ -750,14 +750,14 @@ pub struct NonExportedMacroInvalidAttrs { #[derive(Diagnostic)] #[diag(passes_may_dangle)] -pub struct InvalidMayDangle { +pub(crate) struct InvalidMayDangle { #[primary_span] pub attr_span: Span, } #[derive(LintDiagnostic)] #[diag(passes_unused_duplicate)] -pub struct UnusedDuplicate { +pub(crate) struct UnusedDuplicate { #[suggestion(code = "", applicability = "machine-applicable")] pub this: Span, #[note] @@ -768,7 +768,7 @@ pub struct UnusedDuplicate { #[derive(Diagnostic)] #[diag(passes_unused_multiple)] -pub struct UnusedMultiple { +pub(crate) struct UnusedMultiple { #[primary_span] #[suggestion(code = "", applicability = "machine-applicable")] pub this: Span, @@ -779,7 +779,7 @@ pub struct UnusedMultiple { #[derive(Diagnostic)] #[diag(passes_rustc_lint_opt_ty)] -pub struct RustcLintOptTy { +pub(crate) struct RustcLintOptTy { #[primary_span] pub attr_span: Span, #[label] @@ -788,7 +788,7 @@ pub struct RustcLintOptTy { #[derive(Diagnostic)] #[diag(passes_rustc_lint_opt_deny_field_access)] -pub struct RustcLintOptDenyFieldAccess { +pub(crate) struct RustcLintOptDenyFieldAccess { #[primary_span] pub attr_span: Span, #[label] @@ -797,7 +797,7 @@ pub struct RustcLintOptDenyFieldAccess { #[derive(Diagnostic)] #[diag(passes_collapse_debuginfo)] -pub struct CollapseDebuginfo { +pub(crate) struct CollapseDebuginfo { #[primary_span] pub attr_span: Span, #[label] @@ -806,14 +806,14 @@ pub struct CollapseDebuginfo { #[derive(LintDiagnostic)] #[diag(passes_deprecated_annotation_has_no_effect)] -pub struct DeprecatedAnnotationHasNoEffect { +pub(crate) struct DeprecatedAnnotationHasNoEffect { #[suggestion(applicability = "machine-applicable", code = "")] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_unknown_external_lang_item, code = E0264)] -pub struct UnknownExternLangItem { +pub(crate) struct UnknownExternLangItem { #[primary_span] pub span: Span, pub lang_item: Symbol, @@ -821,25 +821,25 @@ pub struct UnknownExternLangItem { #[derive(Diagnostic)] #[diag(passes_missing_panic_handler)] -pub struct MissingPanicHandler; +pub(crate) struct MissingPanicHandler; #[derive(Diagnostic)] #[diag(passes_panic_unwind_without_std)] #[help] #[note] -pub struct PanicUnwindWithoutStd; +pub(crate) struct PanicUnwindWithoutStd; #[derive(Diagnostic)] #[diag(passes_missing_lang_item)] #[note] #[help] -pub struct MissingLangItem { +pub(crate) struct MissingLangItem { pub name: Symbol, } #[derive(Diagnostic)] #[diag(passes_lang_item_fn_with_track_caller)] -pub struct LangItemWithTrackCaller { +pub(crate) struct LangItemWithTrackCaller { #[primary_span] pub attr_span: Span, pub name: Symbol, @@ -849,7 +849,7 @@ pub struct LangItemWithTrackCaller { #[derive(Diagnostic)] #[diag(passes_lang_item_fn_with_target_feature)] -pub struct LangItemWithTargetFeature { +pub(crate) struct LangItemWithTargetFeature { #[primary_span] pub attr_span: Span, pub name: Symbol, @@ -859,7 +859,7 @@ pub struct LangItemWithTargetFeature { #[derive(Diagnostic)] #[diag(passes_lang_item_on_incorrect_target, code = E0718)] -pub struct LangItemOnIncorrectTarget { +pub(crate) struct LangItemOnIncorrectTarget { #[primary_span] #[label] pub span: Span, @@ -870,14 +870,14 @@ pub struct LangItemOnIncorrectTarget { #[derive(Diagnostic)] #[diag(passes_unknown_lang_item, code = E0522)] -pub struct UnknownLangItem { +pub(crate) struct UnknownLangItem { #[primary_span] #[label] pub span: Span, pub name: Symbol, } -pub struct InvalidAttrAtCrateLevel { +pub(crate) struct InvalidAttrAtCrateLevel { pub span: Span, pub sugg_span: Option, pub name: Symbol, @@ -885,7 +885,7 @@ pub struct InvalidAttrAtCrateLevel { } #[derive(Clone, Copy)] -pub struct ItemFollowingInnerAttr { +pub(crate) struct ItemFollowingInnerAttr { pub span: Span, pub kind: &'static str, } @@ -916,7 +916,7 @@ impl Diagnostic<'_, G> for InvalidAttrAtCrateLevel { #[derive(Diagnostic)] #[diag(passes_duplicate_diagnostic_item_in_crate)] -pub struct DuplicateDiagnosticItemInCrate { +pub(crate) struct DuplicateDiagnosticItemInCrate { #[primary_span] pub duplicate_span: Option, #[note(passes_diagnostic_item_first_defined)] @@ -930,7 +930,7 @@ pub struct DuplicateDiagnosticItemInCrate { #[derive(Diagnostic)] #[diag(passes_layout_abi)] -pub struct LayoutAbi { +pub(crate) struct LayoutAbi { #[primary_span] pub span: Span, pub abi: String, @@ -938,7 +938,7 @@ pub struct LayoutAbi { #[derive(Diagnostic)] #[diag(passes_layout_align)] -pub struct LayoutAlign { +pub(crate) struct LayoutAlign { #[primary_span] pub span: Span, pub align: String, @@ -946,7 +946,7 @@ pub struct LayoutAlign { #[derive(Diagnostic)] #[diag(passes_layout_size)] -pub struct LayoutSize { +pub(crate) struct LayoutSize { #[primary_span] pub span: Span, pub size: String, @@ -954,7 +954,7 @@ pub struct LayoutSize { #[derive(Diagnostic)] #[diag(passes_layout_homogeneous_aggregate)] -pub struct LayoutHomogeneousAggregate { +pub(crate) struct LayoutHomogeneousAggregate { #[primary_span] pub span: Span, pub homogeneous_aggregate: String, @@ -962,7 +962,7 @@ pub struct LayoutHomogeneousAggregate { #[derive(Diagnostic)] #[diag(passes_layout_of)] -pub struct LayoutOf { +pub(crate) struct LayoutOf { #[primary_span] pub span: Span, pub normalized_ty: String, @@ -971,14 +971,14 @@ pub struct LayoutOf { #[derive(Diagnostic)] #[diag(passes_layout_invalid_attribute)] -pub struct LayoutInvalidAttribute { +pub(crate) struct LayoutInvalidAttribute { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_abi_of)] -pub struct AbiOf { +pub(crate) struct AbiOf { #[primary_span] pub span: Span, pub fn_name: Symbol, @@ -987,7 +987,7 @@ pub struct AbiOf { #[derive(Diagnostic)] #[diag(passes_abi_ne)] -pub struct AbiNe { +pub(crate) struct AbiNe { #[primary_span] pub span: Span, pub left: String, @@ -996,14 +996,14 @@ pub struct AbiNe { #[derive(Diagnostic)] #[diag(passes_abi_invalid_attribute)] -pub struct AbiInvalidAttribute { +pub(crate) struct AbiInvalidAttribute { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_unrecognized_field)] -pub struct UnrecognizedField { +pub(crate) struct UnrecognizedField { #[primary_span] pub span: Span, pub name: Symbol, @@ -1011,7 +1011,7 @@ pub struct UnrecognizedField { #[derive(Diagnostic)] #[diag(passes_feature_stable_twice, code = E0711)] -pub struct FeatureStableTwice { +pub(crate) struct FeatureStableTwice { #[primary_span] pub span: Span, pub feature: Symbol, @@ -1021,7 +1021,7 @@ pub struct FeatureStableTwice { #[derive(Diagnostic)] #[diag(passes_feature_previously_declared, code = E0711)] -pub struct FeaturePreviouslyDeclared<'a, 'b> { +pub(crate) struct FeaturePreviouslyDeclared<'a, 'b> { #[primary_span] pub span: Span, pub feature: Symbol, @@ -1029,7 +1029,7 @@ pub struct FeaturePreviouslyDeclared<'a, 'b> { pub prev_declared: &'b str, } -pub struct BreakNonLoop<'a> { +pub(crate) struct BreakNonLoop<'a> { pub span: Span, pub head: Option, pub kind: &'a str, @@ -1084,7 +1084,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'_, G> for BreakNonLoop<'a> { #[derive(Diagnostic)] #[diag(passes_continue_labeled_block, code = E0696)] -pub struct ContinueLabeledBlock { +pub(crate) struct ContinueLabeledBlock { #[primary_span] #[label] pub span: Span, @@ -1094,7 +1094,7 @@ pub struct ContinueLabeledBlock { #[derive(Diagnostic)] #[diag(passes_break_inside_closure, code = E0267)] -pub struct BreakInsideClosure<'a> { +pub(crate) struct BreakInsideClosure<'a> { #[primary_span] #[label] pub span: Span, @@ -1105,7 +1105,7 @@ pub struct BreakInsideClosure<'a> { #[derive(Diagnostic)] #[diag(passes_break_inside_coroutine, code = E0267)] -pub struct BreakInsideCoroutine<'a> { +pub(crate) struct BreakInsideCoroutine<'a> { #[primary_span] #[label] pub span: Span, @@ -1118,7 +1118,7 @@ pub struct BreakInsideCoroutine<'a> { #[derive(Diagnostic)] #[diag(passes_outside_loop, code = E0268)] -pub struct OutsideLoop<'a> { +pub(crate) struct OutsideLoop<'a> { #[primary_span] #[label] pub spans: Vec, @@ -1129,7 +1129,7 @@ pub struct OutsideLoop<'a> { } #[derive(Subdiagnostic)] #[multipart_suggestion(passes_outside_loop_suggestion, applicability = "maybe-incorrect")] -pub struct OutsideLoopSuggestion { +pub(crate) struct OutsideLoopSuggestion { #[suggestion_part(code = "'block: ")] pub block_span: Span, #[suggestion_part(code = " 'block")] @@ -1138,7 +1138,7 @@ pub struct OutsideLoopSuggestion { #[derive(Diagnostic)] #[diag(passes_unlabeled_in_labeled_block, code = E0695)] -pub struct UnlabeledInLabeledBlock<'a> { +pub(crate) struct UnlabeledInLabeledBlock<'a> { #[primary_span] #[label] pub span: Span, @@ -1147,7 +1147,7 @@ pub struct UnlabeledInLabeledBlock<'a> { #[derive(Diagnostic)] #[diag(passes_unlabeled_cf_in_while_condition, code = E0590)] -pub struct UnlabeledCfInWhileCondition<'a> { +pub(crate) struct UnlabeledCfInWhileCondition<'a> { #[primary_span] #[label] pub span: Span, @@ -1156,11 +1156,11 @@ pub struct UnlabeledCfInWhileCondition<'a> { #[derive(LintDiagnostic)] #[diag(passes_undefined_naked_function_abi)] -pub struct UndefinedNakedFunctionAbi; +pub(crate) struct UndefinedNakedFunctionAbi; #[derive(Diagnostic)] #[diag(passes_no_patterns)] -pub struct NoPatterns { +pub(crate) struct NoPatterns { #[primary_span] pub span: Span, } @@ -1168,12 +1168,12 @@ pub struct NoPatterns { #[derive(Diagnostic)] #[diag(passes_params_not_allowed)] #[help] -pub struct ParamsNotAllowed { +pub(crate) struct ParamsNotAllowed { #[primary_span] pub span: Span, } -pub struct NakedFunctionsAsmBlock { +pub(crate) struct NakedFunctionsAsmBlock { pub span: Span, pub multiple_asms: Vec, pub non_asms: Vec, @@ -1197,14 +1197,14 @@ impl Diagnostic<'_, G> for NakedFunctionsAsmBlock { #[derive(Diagnostic)] #[diag(passes_naked_functions_operands, code = E0787)] -pub struct NakedFunctionsOperands { +pub(crate) struct NakedFunctionsOperands { #[primary_span] pub unsupported_operands: Vec, } #[derive(Diagnostic)] #[diag(passes_naked_functions_asm_options, code = E0787)] -pub struct NakedFunctionsAsmOptions { +pub(crate) struct NakedFunctionsAsmOptions { #[primary_span] pub span: Span, pub unsupported_options: String, @@ -1212,7 +1212,7 @@ pub struct NakedFunctionsAsmOptions { #[derive(Diagnostic)] #[diag(passes_naked_functions_must_use_noreturn, code = E0787)] -pub struct NakedFunctionsMustUseNoreturn { +pub(crate) struct NakedFunctionsMustUseNoreturn { #[primary_span] pub span: Span, #[suggestion(code = ", options(noreturn)", applicability = "machine-applicable")] @@ -1221,7 +1221,7 @@ pub struct NakedFunctionsMustUseNoreturn { #[derive(Diagnostic)] #[diag(passes_naked_functions_incompatible_attribute, code = E0736)] -pub struct NakedFunctionIncompatibleAttribute { +pub(crate) struct NakedFunctionIncompatibleAttribute { #[primary_span] #[label] pub span: Span, @@ -1232,7 +1232,7 @@ pub struct NakedFunctionIncompatibleAttribute { #[derive(Diagnostic)] #[diag(passes_attr_only_in_functions)] -pub struct AttrOnlyInFunctions { +pub(crate) struct AttrOnlyInFunctions { #[primary_span] pub span: Span, pub attr: Symbol, @@ -1240,7 +1240,7 @@ pub struct AttrOnlyInFunctions { #[derive(Diagnostic)] #[diag(passes_multiple_rustc_main, code = E0137)] -pub struct MultipleRustcMain { +pub(crate) struct MultipleRustcMain { #[primary_span] pub span: Span, #[label(passes_first)] @@ -1251,7 +1251,7 @@ pub struct MultipleRustcMain { #[derive(Diagnostic)] #[diag(passes_multiple_start_functions, code = E0138)] -pub struct MultipleStartFunctions { +pub(crate) struct MultipleStartFunctions { #[primary_span] pub span: Span, #[label] @@ -1262,12 +1262,12 @@ pub struct MultipleStartFunctions { #[derive(Diagnostic)] #[diag(passes_extern_main)] -pub struct ExternMain { +pub(crate) struct ExternMain { #[primary_span] pub span: Span, } -pub struct NoMainErr { +pub(crate) struct NoMainErr { pub sp: Span, pub crate_name: Symbol, pub has_filename: bool, @@ -1321,7 +1321,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NoMainErr { } } -pub struct DuplicateLangItem { +pub(crate) struct DuplicateLangItem { pub local_span: Option, pub lang_item_name: Symbol, pub crate_name: Symbol, @@ -1386,7 +1386,7 @@ impl Diagnostic<'_, G> for DuplicateLangItem { #[derive(Diagnostic)] #[diag(passes_incorrect_target, code = E0718)] -pub struct IncorrectTarget<'a> { +pub(crate) struct IncorrectTarget<'a> { #[primary_span] pub span: Span, #[label] @@ -1400,21 +1400,21 @@ pub struct IncorrectTarget<'a> { #[derive(LintDiagnostic)] #[diag(passes_useless_assignment)] -pub struct UselessAssignment<'a> { +pub(crate) struct UselessAssignment<'a> { pub is_field_assign: bool, pub ty: Ty<'a>, } #[derive(LintDiagnostic)] #[diag(passes_only_has_effect_on)] -pub struct OnlyHasEffectOn { +pub(crate) struct OnlyHasEffectOn { pub attr_name: Symbol, pub target_name: String, } #[derive(Diagnostic)] #[diag(passes_object_lifetime_err)] -pub struct ObjectLifetimeErr { +pub(crate) struct ObjectLifetimeErr { #[primary_span] pub span: Span, pub repr: String, @@ -1423,13 +1423,13 @@ pub struct ObjectLifetimeErr { #[derive(Diagnostic)] #[diag(passes_unrecognized_repr_hint, code = E0552)] #[help] -pub struct UnrecognizedReprHint { +pub(crate) struct UnrecognizedReprHint { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -pub enum AttrApplication { +pub(crate) enum AttrApplication { #[diag(passes_attr_application_enum, code = E0517)] Enum { #[primary_span] @@ -1469,7 +1469,7 @@ pub enum AttrApplication { #[derive(Diagnostic)] #[diag(passes_transparent_incompatible, code = E0692)] -pub struct TransparentIncompatible { +pub(crate) struct TransparentIncompatible { #[primary_span] pub hint_spans: Vec, pub target: String, @@ -1477,14 +1477,14 @@ pub struct TransparentIncompatible { #[derive(Diagnostic)] #[diag(passes_deprecated_attribute, code = E0549)] -pub struct DeprecatedAttribute { +pub(crate) struct DeprecatedAttribute { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_useless_stability)] -pub struct UselessStability { +pub(crate) struct UselessStability { #[primary_span] #[label] pub span: Span, @@ -1494,7 +1494,7 @@ pub struct UselessStability { #[derive(Diagnostic)] #[diag(passes_cannot_stabilize_deprecated)] -pub struct CannotStabilizeDeprecated { +pub(crate) struct CannotStabilizeDeprecated { #[primary_span] #[label] pub span: Span, @@ -1504,7 +1504,7 @@ pub struct CannotStabilizeDeprecated { #[derive(Diagnostic)] #[diag(passes_missing_stability_attr)] -pub struct MissingStabilityAttr<'a> { +pub(crate) struct MissingStabilityAttr<'a> { #[primary_span] pub span: Span, pub descr: &'a str, @@ -1512,7 +1512,7 @@ pub struct MissingStabilityAttr<'a> { #[derive(Diagnostic)] #[diag(passes_missing_const_stab_attr)] -pub struct MissingConstStabAttr<'a> { +pub(crate) struct MissingConstStabAttr<'a> { #[primary_span] pub span: Span, pub descr: &'a str, @@ -1521,14 +1521,14 @@ pub struct MissingConstStabAttr<'a> { #[derive(Diagnostic)] #[diag(passes_trait_impl_const_stable)] #[note] -pub struct TraitImplConstStable { +pub(crate) struct TraitImplConstStable { #[primary_span] pub span: Span, } #[derive(Diagnostic)] #[diag(passes_unknown_feature, code = E0635)] -pub struct UnknownFeature { +pub(crate) struct UnknownFeature { #[primary_span] pub span: Span, pub feature: Symbol, @@ -1536,7 +1536,7 @@ pub struct UnknownFeature { #[derive(Diagnostic)] #[diag(passes_implied_feature_not_exist)] -pub struct ImpliedFeatureNotExist { +pub(crate) struct ImpliedFeatureNotExist { #[primary_span] pub span: Span, pub feature: Symbol, @@ -1545,14 +1545,14 @@ pub struct ImpliedFeatureNotExist { #[derive(Diagnostic)] #[diag(passes_duplicate_feature_err, code = E0636)] -pub struct DuplicateFeatureErr { +pub(crate) struct DuplicateFeatureErr { #[primary_span] pub span: Span, pub feature: Symbol, } #[derive(Diagnostic)] #[diag(passes_missing_const_err)] -pub struct MissingConstErr { +pub(crate) struct MissingConstErr { #[primary_span] #[help] pub fn_sig_span: Span, @@ -1561,7 +1561,7 @@ pub struct MissingConstErr { } #[derive(LintDiagnostic)] -pub enum MultipleDeadCodes<'tcx> { +pub(crate) enum MultipleDeadCodes<'tcx> { #[diag(passes_dead_codes)] DeadCodes { multiple: bool, @@ -1592,7 +1592,7 @@ pub enum MultipleDeadCodes<'tcx> { #[derive(Subdiagnostic)] #[label(passes_parent_info)] -pub struct ParentInfo<'tcx> { +pub(crate) struct ParentInfo<'tcx> { pub num: usize, pub descr: &'tcx str, pub parent_descr: &'tcx str, @@ -1602,14 +1602,14 @@ pub struct ParentInfo<'tcx> { #[derive(Subdiagnostic)] #[note(passes_ignored_derived_impls)] -pub struct IgnoredDerivedImpls { +pub(crate) struct IgnoredDerivedImpls { pub name: Symbol, pub trait_list: DiagSymbolList, pub trait_list_len: usize, } #[derive(Subdiagnostic)] -pub enum ChangeFields { +pub(crate) enum ChangeFields { #[multipart_suggestion( passes_change_fields_to_be_of_unit_type, applicability = "has-placeholders" @@ -1633,14 +1633,14 @@ pub(crate) struct ProcMacroBadSig { #[derive(Diagnostic)] #[diag(passes_skipping_const_checks)] -pub struct SkippingConstChecks { +pub(crate) struct SkippingConstChecks { #[primary_span] pub span: Span, } #[derive(LintDiagnostic)] #[diag(passes_unreachable_due_to_uninhabited)] -pub struct UnreachableDueToUninhabited<'desc, 'tcx> { +pub(crate) struct UnreachableDueToUninhabited<'desc, 'tcx> { pub descr: &'desc str, #[label] pub expr: Span, @@ -1653,20 +1653,20 @@ pub struct UnreachableDueToUninhabited<'desc, 'tcx> { #[derive(LintDiagnostic)] #[diag(passes_unused_var_maybe_capture_ref)] #[help] -pub struct UnusedVarMaybeCaptureRef { +pub(crate) struct UnusedVarMaybeCaptureRef { pub name: String, } #[derive(LintDiagnostic)] #[diag(passes_unused_capture_maybe_capture_ref)] #[help] -pub struct UnusedCaptureMaybeCaptureRef { +pub(crate) struct UnusedCaptureMaybeCaptureRef { pub name: String, } #[derive(LintDiagnostic)] #[diag(passes_unused_var_remove_field)] -pub struct UnusedVarRemoveField { +pub(crate) struct UnusedVarRemoveField { pub name: String, #[subdiagnostic] pub sugg: UnusedVarRemoveFieldSugg, @@ -1677,7 +1677,7 @@ pub struct UnusedVarRemoveField { passes_unused_var_remove_field_suggestion, applicability = "machine-applicable" )] -pub struct UnusedVarRemoveFieldSugg { +pub(crate) struct UnusedVarRemoveFieldSugg { #[suggestion_part(code = "")] pub spans: Vec, } @@ -1685,20 +1685,20 @@ pub struct UnusedVarRemoveFieldSugg { #[derive(LintDiagnostic)] #[diag(passes_unused_var_assigned_only)] #[note] -pub struct UnusedVarAssignedOnly { +pub(crate) struct UnusedVarAssignedOnly { pub name: String, } #[derive(LintDiagnostic)] #[diag(passes_unnecessary_stable_feature)] -pub struct UnnecessaryStableFeature { +pub(crate) struct UnnecessaryStableFeature { pub feature: Symbol, pub since: Symbol, } #[derive(LintDiagnostic)] #[diag(passes_unnecessary_partial_stable_feature)] -pub struct UnnecessaryPartialStableFeature { +pub(crate) struct UnnecessaryPartialStableFeature { #[suggestion(code = "{implies}", applicability = "maybe-incorrect")] pub span: Span, #[suggestion(passes_suggestion_remove, code = "", applicability = "maybe-incorrect")] @@ -1711,25 +1711,25 @@ pub struct UnnecessaryPartialStableFeature { #[derive(LintDiagnostic)] #[diag(passes_ineffective_unstable_impl)] #[note] -pub struct IneffectiveUnstableImpl; +pub(crate) struct IneffectiveUnstableImpl; #[derive(LintDiagnostic)] #[diag(passes_unused_assign)] #[help] -pub struct UnusedAssign { +pub(crate) struct UnusedAssign { pub name: String, } #[derive(LintDiagnostic)] #[diag(passes_unused_assign_passed)] #[help] -pub struct UnusedAssignPassed { +pub(crate) struct UnusedAssignPassed { pub name: String, } #[derive(LintDiagnostic)] #[diag(passes_unused_variable_try_prefix)] -pub struct UnusedVariableTryPrefix { +pub(crate) struct UnusedVariableTryPrefix { #[label] pub label: Option, #[subdiagnostic] @@ -1740,7 +1740,7 @@ pub struct UnusedVariableTryPrefix { } #[derive(Subdiagnostic)] -pub enum UnusedVariableSugg { +pub(crate) enum UnusedVariableSugg { #[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")] TryPrefixSugg { #[suggestion_part(code = "_{name}")] @@ -1755,7 +1755,7 @@ pub enum UnusedVariableSugg { }, } -pub struct UnusedVariableStringInterp { +pub(crate) struct UnusedVariableStringInterp { pub lit: Span, pub lo: Span, pub hi: Span, @@ -1778,14 +1778,14 @@ impl Subdiagnostic for UnusedVariableStringInterp { #[derive(LintDiagnostic)] #[diag(passes_unused_variable_try_ignore)] -pub struct UnusedVarTryIgnore { +pub(crate) struct UnusedVarTryIgnore { #[subdiagnostic] pub sugg: UnusedVarTryIgnoreSugg, } #[derive(Subdiagnostic)] #[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")] -pub struct UnusedVarTryIgnoreSugg { +pub(crate) struct UnusedVarTryIgnoreSugg { #[suggestion_part(code = "{name}: _")] pub shorthands: Vec, #[suggestion_part(code = "_")] @@ -1796,14 +1796,14 @@ pub struct UnusedVarTryIgnoreSugg { #[derive(LintDiagnostic)] #[diag(passes_attr_crate_level)] #[note] -pub struct AttrCrateLevelOnly { +pub(crate) struct AttrCrateLevelOnly { #[subdiagnostic] pub sugg: Option, } #[derive(Subdiagnostic)] #[suggestion(passes_suggestion, applicability = "maybe-incorrect", code = "!", style = "verbose")] -pub struct AttrCrateLevelOnlySugg { +pub(crate) struct AttrCrateLevelOnlySugg { #[primary_span] pub attr: Span, } diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 71b0ebb0e2170..8038afb955e28 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -359,6 +359,6 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> { } } -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { providers.get_lang_items = get_lang_items; } diff --git a/compiler/rustc_passes/src/lib.rs b/compiler/rustc_passes/src/lib.rs index a0f5f98aafc86..664da65068dfc 100644 --- a/compiler/rustc_passes/src/lib.rs +++ b/compiler/rustc_passes/src/lib.rs @@ -12,6 +12,7 @@ #![feature(map_try_insert)] #![feature(rustdoc_internals)] #![feature(try_blocks)] +#![warn(unreachable_pub)] // tidy-alphabetical-end use rustc_middle::query::Providers; diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index e60985ba16fbf..9d5766865c72f 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -16,7 +16,7 @@ use rustc_span::{sym, Span}; use crate::errors::{FeaturePreviouslyDeclared, FeatureStableTwice}; -pub struct LibFeatureCollector<'tcx> { +struct LibFeatureCollector<'tcx> { tcx: TyCtxt<'tcx>, lib_features: LibFeatures, } @@ -153,6 +153,6 @@ fn lib_features(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> LibFeatures { collector.lib_features } -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { providers.lib_features = lib_features; } diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index d3b85da4630ef..db3eaea68b5c2 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -178,7 +178,7 @@ fn check_liveness(tcx: TyCtxt<'_>, def_id: LocalDefId) { lsets.warn_about_unused_args(&body, entry_ln); } -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { check_liveness, ..*providers }; } diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index dee8ba7e87dfd..8d9e00b9f3c8f 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -500,6 +500,6 @@ fn reachable_set(tcx: TyCtxt<'_>, (): ()) -> LocalDefIdSet { reachable_context.reachable_symbols } -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { reachable_set, ..*providers }; } diff --git a/compiler/rustc_passes/src/upvars.rs b/compiler/rustc_passes/src/upvars.rs index f2454514e4d32..0544d08f5b196 100644 --- a/compiler/rustc_passes/src/upvars.rs +++ b/compiler/rustc_passes/src/upvars.rs @@ -9,7 +9,7 @@ use rustc_middle::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_span::Span; -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { providers.upvars_mentioned = |tcx, def_id| { if !tcx.is_closure_like(def_id) { return None; diff --git a/compiler/rustc_passes/src/weak_lang_items.rs b/compiler/rustc_passes/src/weak_lang_items.rs index 90691ca17908b..020128f29c59b 100644 --- a/compiler/rustc_passes/src/weak_lang_items.rs +++ b/compiler/rustc_passes/src/weak_lang_items.rs @@ -15,7 +15,11 @@ use crate::errors::{ /// Checks the crate for usage of weak lang items, returning a vector of all the /// lang items required by this crate, but not defined yet. -pub fn check_crate(tcx: TyCtxt<'_>, items: &mut lang_items::LanguageItems, krate: &ast::Crate) { +pub(crate) fn check_crate( + tcx: TyCtxt<'_>, + items: &mut lang_items::LanguageItems, + krate: &ast::Crate, +) { // These are never called by user code, they're generated by the compiler. // They will never implicitly be added to the `missing` array unless we do // so here. From 653ee7bc3aa0a28eabb796cbe14d185b49fe3e6d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 16:24:38 +1000 Subject: [PATCH 11/15] Add `warn(unreachable_pub)` to `rustc_pattern_analysis`. --- compiler/rustc_pattern_analysis/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index 6c9c848bb10ae..fec44d5af55da 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -6,6 +6,7 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] #![cfg_attr(feature = "rustc", feature(let_chains))] +#![warn(unreachable_pub)] // tidy-alphabetical-end pub mod constructor; From 71bffef4f9d1f8d34a586031532d6629b0bb33dd Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 16:29:14 +1000 Subject: [PATCH 12/15] Add `warn(unreachable_pub)` to `rustc_privacy`. --- compiler/rustc_privacy/src/errors.rs | 18 +++++++++--------- compiler/rustc_privacy/src/lib.rs | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_privacy/src/errors.rs b/compiler/rustc_privacy/src/errors.rs index 89face1075091..34553c2b90ab8 100644 --- a/compiler/rustc_privacy/src/errors.rs +++ b/compiler/rustc_privacy/src/errors.rs @@ -5,7 +5,7 @@ use rustc_span::{Span, Symbol}; #[derive(Diagnostic)] #[diag(privacy_field_is_private, code = E0451)] -pub struct FieldIsPrivate { +pub(crate) struct FieldIsPrivate { #[primary_span] pub span: Span, pub field_name: Symbol, @@ -16,7 +16,7 @@ pub struct FieldIsPrivate { } #[derive(Subdiagnostic)] -pub enum FieldIsPrivateLabel { +pub(crate) enum FieldIsPrivateLabel { #[label(privacy_field_is_private_is_update_syntax_label)] IsUpdateSyntax { #[primary_span] @@ -32,7 +32,7 @@ pub enum FieldIsPrivateLabel { #[derive(Diagnostic)] #[diag(privacy_item_is_private)] -pub struct ItemIsPrivate<'a> { +pub(crate) struct ItemIsPrivate<'a> { #[primary_span] #[label] pub span: Span, @@ -42,7 +42,7 @@ pub struct ItemIsPrivate<'a> { #[derive(Diagnostic)] #[diag(privacy_unnamed_item_is_private)] -pub struct UnnamedItemIsPrivate { +pub(crate) struct UnnamedItemIsPrivate { #[primary_span] pub span: Span, pub kind: &'static str, @@ -50,7 +50,7 @@ pub struct UnnamedItemIsPrivate { #[derive(Diagnostic)] #[diag(privacy_in_public_interface, code = E0446)] -pub struct InPublicInterface<'a> { +pub(crate) struct InPublicInterface<'a> { #[primary_span] #[label] pub span: Span, @@ -63,7 +63,7 @@ pub struct InPublicInterface<'a> { #[derive(Diagnostic)] #[diag(privacy_report_effective_visibility)] -pub struct ReportEffectiveVisibility { +pub(crate) struct ReportEffectiveVisibility { #[primary_span] pub span: Span, pub descr: String, @@ -71,7 +71,7 @@ pub struct ReportEffectiveVisibility { #[derive(LintDiagnostic)] #[diag(privacy_from_private_dep_in_public_interface)] -pub struct FromPrivateDependencyInPublicInterface<'a> { +pub(crate) struct FromPrivateDependencyInPublicInterface<'a> { pub kind: &'a str, pub descr: DiagArgFromDisplay<'a>, pub krate: Symbol, @@ -79,7 +79,7 @@ pub struct FromPrivateDependencyInPublicInterface<'a> { #[derive(LintDiagnostic)] #[diag(privacy_unnameable_types_lint)] -pub struct UnnameableTypesLint<'a> { +pub(crate) struct UnnameableTypesLint<'a> { #[label] pub span: Span, pub kind: &'a str, @@ -93,7 +93,7 @@ pub struct UnnameableTypesLint<'a> { // See https://rust-lang.github.io/rfcs/2145-type-privacy.html for more details. #[derive(LintDiagnostic)] #[diag(privacy_private_interface_or_bounds_lint)] -pub struct PrivateInterfacesOrBoundsLint<'a> { +pub(crate) struct PrivateInterfacesOrBoundsLint<'a> { #[label(privacy_item_label)] pub item_span: Span, pub item_kind: &'a str, diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 9f78215bfd1f9..572f71d7c77fc 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -6,6 +6,7 @@ #![feature(let_chains)] #![feature(rustdoc_internals)] #![feature(try_blocks)] +#![warn(unreachable_pub)] // tidy-alphabetical-end mod errors; @@ -1497,7 +1498,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> { self.effective_visibilities.effective_vis(def_id).copied() } - pub fn check_item(&mut self, id: ItemId) { + fn check_item(&mut self, id: ItemId) { let tcx = self.tcx; let def_id = id.owner_id.def_id; let item_visibility = tcx.local_visibility(def_id); From 2eea2d2cf105255b1ce7bd0eeb0d326a06adefc8 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 16:39:19 +1000 Subject: [PATCH 13/15] Add `warn(unreachable_pub)` to `rustc_query_impl`. --- compiler/rustc_query_impl/src/lib.rs | 1 + compiler/rustc_query_impl/src/plumbing.rs | 44 +++++++++++++---------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index f4a4c602f69f0..a6c863a6b7b76 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -8,6 +8,7 @@ #![feature(min_specialization)] #![feature(rustc_attrs)] #![feature(rustdoc_internals)] +#![warn(unreachable_pub)] // tidy-alphabetical-end use field_offset::offset_of; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index c064b2bd6c16c..6a6698b019caa 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -541,7 +541,7 @@ macro_rules! expand_if_cached { /// Don't show the backtrace for query system by default /// use `RUST_BACKTRACE=full` to show all the backtraces #[inline(never)] -pub fn __rust_begin_short_backtrace(f: F) -> T +pub(crate) fn __rust_begin_short_backtrace(f: F) -> T where F: FnOnce() -> T, { @@ -557,17 +557,17 @@ macro_rules! define_queries { $($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => { - pub(crate) mod query_impl { $(pub mod $name { + pub(crate) mod query_impl { $(pub(crate) mod $name { use super::super::*; use std::marker::PhantomData; - pub mod get_query_incr { + pub(crate) mod get_query_incr { use super::*; // Adding `__rust_end_short_backtrace` marker to backtraces so that we emit the frames // when `RUST_BACKTRACE=1`, add a new mod with `$name` here is to allow duplicate naming #[inline(never)] - pub fn __rust_end_short_backtrace<'tcx>( + pub(crate) fn __rust_end_short_backtrace<'tcx>( tcx: TyCtxt<'tcx>, span: Span, key: queries::$name::Key<'tcx>, @@ -585,11 +585,11 @@ macro_rules! define_queries { } } - pub mod get_query_non_incr { + pub(crate) mod get_query_non_incr { use super::*; #[inline(never)] - pub fn __rust_end_short_backtrace<'tcx>( + pub(crate) fn __rust_end_short_backtrace<'tcx>( tcx: TyCtxt<'tcx>, span: Span, key: queries::$name::Key<'tcx>, @@ -604,7 +604,9 @@ macro_rules! define_queries { } } - pub fn dynamic_query<'tcx>() -> DynamicQuery<'tcx, queries::$name::Storage<'tcx>> { + pub(crate) fn dynamic_query<'tcx>() + -> DynamicQuery<'tcx, queries::$name::Storage<'tcx>> + { DynamicQuery { name: stringify!($name), eval_always: is_eval_always!([$($modifiers)*]), @@ -667,7 +669,7 @@ macro_rules! define_queries { } #[derive(Copy, Clone, Default)] - pub struct QueryType<'tcx> { + pub(crate) struct QueryType<'tcx> { data: PhantomData<&'tcx ()> } @@ -696,7 +698,7 @@ macro_rules! define_queries { } } - pub fn try_collect_active_jobs<'tcx>(tcx: TyCtxt<'tcx>, qmap: &mut QueryMap) { + pub(crate) fn try_collect_active_jobs<'tcx>(tcx: TyCtxt<'tcx>, qmap: &mut QueryMap) { let make_query = |tcx, key| { let kind = rustc_middle::dep_graph::dep_kinds::$name; let name = stringify!($name); @@ -711,11 +713,17 @@ macro_rules! define_queries { // don't `unwrap()` here, just manually check for `None` and do best-effort error // reporting. if res.is_none() { - tracing::warn!("Failed to collect active jobs for query with name `{}`!", stringify!($name)); + tracing::warn!( + "Failed to collect active jobs for query with name `{}`!", + stringify!($name) + ); } } - pub fn alloc_self_profile_query_strings<'tcx>(tcx: TyCtxt<'tcx>, string_cache: &mut QueryKeyStringCache) { + pub(crate) fn alloc_self_profile_query_strings<'tcx>( + tcx: TyCtxt<'tcx>, + string_cache: &mut QueryKeyStringCache + ) { $crate::profiling_support::alloc_self_profile_query_strings_for_query_cache( tcx, stringify!($name), @@ -725,7 +733,7 @@ macro_rules! define_queries { } item_if_cached! { [$($modifiers)*] { - pub fn encode_query_results<'tcx>( + pub(crate) fn encode_query_results<'tcx>( tcx: TyCtxt<'tcx>, encoder: &mut CacheEncoder<'_, 'tcx>, query_result_index: &mut EncodedDepNodeIndex @@ -739,7 +747,7 @@ macro_rules! define_queries { } }} - pub fn query_key_hash_verify<'tcx>(tcx: TyCtxt<'tcx>) { + pub(crate) fn query_key_hash_verify<'tcx>(tcx: TyCtxt<'tcx>) { $crate::plumbing::query_key_hash_verify( query_impl::$name::QueryType::config(tcx), QueryCtxt::new(tcx), @@ -795,7 +803,7 @@ macro_rules! define_queries { use rustc_query_system::dep_graph::FingerprintStyle; // We use this for most things when incr. comp. is turned off. - pub fn Null<'tcx>() -> DepKindStruct<'tcx> { + pub(crate) fn Null<'tcx>() -> DepKindStruct<'tcx> { DepKindStruct { is_anon: false, is_eval_always: false, @@ -807,7 +815,7 @@ macro_rules! define_queries { } // We use this for the forever-red node. - pub fn Red<'tcx>() -> DepKindStruct<'tcx> { + pub(crate) fn Red<'tcx>() -> DepKindStruct<'tcx> { DepKindStruct { is_anon: false, is_eval_always: false, @@ -818,7 +826,7 @@ macro_rules! define_queries { } } - pub fn TraitSelect<'tcx>() -> DepKindStruct<'tcx> { + pub(crate) fn TraitSelect<'tcx>() -> DepKindStruct<'tcx> { DepKindStruct { is_anon: true, is_eval_always: false, @@ -829,7 +837,7 @@ macro_rules! define_queries { } } - pub fn CompileCodegenUnit<'tcx>() -> DepKindStruct<'tcx> { + pub(crate) fn CompileCodegenUnit<'tcx>() -> DepKindStruct<'tcx> { DepKindStruct { is_anon: false, is_eval_always: false, @@ -840,7 +848,7 @@ macro_rules! define_queries { } } - pub fn CompileMonoItem<'tcx>() -> DepKindStruct<'tcx> { + pub(crate) fn CompileMonoItem<'tcx>() -> DepKindStruct<'tcx> { DepKindStruct { is_anon: false, is_eval_always: false, From afc58beebe2366a09baaf622e9834bdae25cc510 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 16:55:43 +1000 Subject: [PATCH 14/15] Add `warn(unreachable_pub)` to `rustc_query_system`. --- .../rustc_query_system/src/dep_graph/serialized.rs | 6 +++--- compiler/rustc_query_system/src/error.rs | 14 +++++++------- compiler/rustc_query_system/src/lib.rs | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_query_system/src/dep_graph/serialized.rs b/compiler/rustc_query_system/src/dep_graph/serialized.rs index ab4a8be0fbfb5..a4fb0a5b07220 100644 --- a/compiler/rustc_query_system/src/dep_graph/serialized.rs +++ b/compiler/rustc_query_system/src/dep_graph/serialized.rs @@ -617,14 +617,14 @@ impl EncoderState { } } -pub struct GraphEncoder { +pub(crate) struct GraphEncoder { profiler: SelfProfilerRef, status: Lock>>, record_graph: Option>, } impl GraphEncoder { - pub fn new( + pub(crate) fn new( encoder: FileEncoder, prev_node_count: usize, record_graph: bool, @@ -723,7 +723,7 @@ impl GraphEncoder { ) } - pub fn finish(&self) -> FileEncodeResult { + pub(crate) fn finish(&self) -> FileEncodeResult { let _prof_timer = self.profiler.generic_activity("incr_comp_encode_dep_graph_finish"); self.status.lock().take().unwrap().finish(&self.profiler) diff --git a/compiler/rustc_query_system/src/error.rs b/compiler/rustc_query_system/src/error.rs index 9db6fac8036a9..860f2e66915f3 100644 --- a/compiler/rustc_query_system/src/error.rs +++ b/compiler/rustc_query_system/src/error.rs @@ -5,7 +5,7 @@ use rustc_span::{Span, Symbol}; #[derive(Subdiagnostic)] #[note(query_system_cycle_stack_middle)] -pub struct CycleStack { +pub(crate) struct CycleStack { #[primary_span] pub span: Span, pub desc: String, @@ -20,7 +20,7 @@ pub enum HandleCycleError { } #[derive(Subdiagnostic)] -pub enum StackCount { +pub(crate) enum StackCount { #[note(query_system_cycle_stack_single)] Single, #[note(query_system_cycle_stack_multiple)] @@ -28,7 +28,7 @@ pub enum StackCount { } #[derive(Subdiagnostic)] -pub enum Alias { +pub(crate) enum Alias { #[note(query_system_cycle_recursive_ty_alias)] #[help(query_system_cycle_recursive_ty_alias_help1)] #[help(query_system_cycle_recursive_ty_alias_help2)] @@ -39,7 +39,7 @@ pub enum Alias { #[derive(Subdiagnostic)] #[note(query_system_cycle_usage)] -pub struct CycleUsage { +pub(crate) struct CycleUsage { #[primary_span] pub span: Span, pub usage: String, @@ -47,7 +47,7 @@ pub struct CycleUsage { #[derive(Diagnostic)] #[diag(query_system_cycle, code = E0391)] -pub struct Cycle { +pub(crate) struct Cycle { #[primary_span] pub span: Span, pub stack_bottom: String, @@ -65,14 +65,14 @@ pub struct Cycle { #[derive(Diagnostic)] #[diag(query_system_reentrant)] -pub struct Reentrant; +pub(crate) struct Reentrant; #[derive(Diagnostic)] #[diag(query_system_increment_compilation)] #[help] #[note(query_system_increment_compilation_note1)] #[note(query_system_increment_compilation_note2)] -pub struct IncrementCompilation { +pub(crate) struct IncrementCompilation { pub run_cmd: String, pub dep_node: String, } diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index 7a50a9534c21f..ba7a631fb5419 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -5,6 +5,7 @@ #![feature(hash_raw_entry)] #![feature(let_chains)] #![feature(min_specialization)] +#![warn(unreachable_pub)] // tidy-alphabetical-end pub mod cache; From 7a71a914f62045989d85cb8eb0e6bde16ffe4f3e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 16:56:35 +1000 Subject: [PATCH 15/15] Add `warn(unreachable_pub)` to `rustc_resolve`. --- compiler/rustc_resolve/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 02fdc1ae6685e..8ffd00d1b2e60 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -21,6 +21,7 @@ #![feature(let_chains)] #![feature(rustc_attrs)] #![feature(rustdoc_internals)] +#![warn(unreachable_pub)] // tidy-alphabetical-end use std::cell::{Cell, RefCell};