Skip to content

Commit 7e23a44

Browse files
Rollup merge of #129732 - nnethercote:unreachable_pub-3, r=Urgau
Add `unreachable_pub`, round 3 A follow-up to #129648. r? `@Urgau`
2 parents 7dc2cab + 7a71a91 commit 7e23a44

File tree

56 files changed

+403
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+403
-347
lines changed

compiler/rustc_macros/src/diagnostics/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use synstructure::Structure;
5555
///
5656
/// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`:
5757
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html>
58-
pub fn diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
58+
pub(super) fn diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
5959
s.underscore_const(true);
6060
DiagnosticDerive::new(s).into_tokens()
6161
}
@@ -102,7 +102,7 @@ pub fn diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
102102
///
103103
/// See rustc dev guide for more examples on using the `#[derive(LintDiagnostic)]`:
104104
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html#reference>
105-
pub fn lint_diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
105+
pub(super) fn lint_diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
106106
s.underscore_const(true);
107107
LintDiagnosticDerive::new(s).into_tokens()
108108
}
@@ -153,7 +153,7 @@ pub fn lint_diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
153153
///
154154
/// diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident });
155155
/// ```
156-
pub fn subdiagnostic_derive(mut s: Structure<'_>) -> TokenStream {
156+
pub(super) fn subdiagnostic_derive(mut s: Structure<'_>) -> TokenStream {
157157
s.underscore_const(true);
158158
SubdiagnosticDerive::new().into_tokens(s)
159159
}

compiler/rustc_macros/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(proc_macro_diagnostic)]
77
#![feature(proc_macro_span)]
88
#![feature(proc_macro_tracked_env)]
9+
#![warn(unreachable_pub)]
910
// tidy-alphabetical-end
1011

1112
use proc_macro::TokenStream;

compiler/rustc_macros/src/lift.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use quote::quote;
22
use syn::parse_quote;
33

4-
pub fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
4+
pub(super) fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
55
s.add_bounds(synstructure::AddBounds::Generics);
66
s.bind_with(|_| synstructure::BindStyle::Move);
77
s.underscore_const(true);

compiler/rustc_macros/src/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ fn add_query_desc_cached_impl(
307307
});
308308
}
309309

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

313313
let mut query_stream = quote! {};

compiler/rustc_macros/src/serialize.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use quote::{quote, quote_spanned};
33
use syn::parse_quote;
44
use syn::spanned::Spanned;
55

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

23-
pub fn meta_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
25+
pub(super) fn meta_decodable_derive(
26+
mut s: synstructure::Structure<'_>,
27+
) -> proc_macro2::TokenStream {
2428
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
2529
s.add_impl_generic(parse_quote! { 'tcx });
2630
}
@@ -32,7 +36,7 @@ pub fn meta_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
3236
decodable_body(s, decoder_ty)
3337
}
3438

35-
pub fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
39+
pub(super) fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
3640
let decoder_ty = quote! { __D };
3741
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_span::SpanDecoder });
3842
s.add_bounds(synstructure::AddBounds::Generics);
@@ -41,7 +45,9 @@ pub fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::Toke
4145
decodable_body(s, decoder_ty)
4246
}
4347

44-
pub fn decodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
48+
pub(super) fn decodable_generic_derive(
49+
mut s: synstructure::Structure<'_>,
50+
) -> proc_macro2::TokenStream {
4551
let decoder_ty = quote! { __D };
4652
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_serialize::Decoder });
4753
s.add_bounds(synstructure::AddBounds::Generics);
@@ -123,7 +129,9 @@ fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream {
123129
quote_spanned! { field_span=> #decode_inner_method(#__decoder) }
124130
}
125131

126-
pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
132+
pub(super) fn type_encodable_derive(
133+
mut s: synstructure::Structure<'_>,
134+
) -> proc_macro2::TokenStream {
127135
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
128136
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
129137
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
@@ -140,7 +148,9 @@ pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
140148
encodable_body(s, encoder_ty, false)
141149
}
142150

143-
pub fn meta_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
151+
pub(super) fn meta_encodable_derive(
152+
mut s: synstructure::Structure<'_>,
153+
) -> proc_macro2::TokenStream {
144154
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
145155
s.add_impl_generic(parse_quote! { 'tcx });
146156
}
@@ -152,7 +162,7 @@ pub fn meta_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
152162
encodable_body(s, encoder_ty, true)
153163
}
154164

155-
pub fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
165+
pub(super) fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
156166
let encoder_ty = quote! { __E };
157167
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_span::SpanEncoder });
158168
s.add_bounds(synstructure::AddBounds::Generics);
@@ -161,7 +171,9 @@ pub fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::Toke
161171
encodable_body(s, encoder_ty, false)
162172
}
163173

164-
pub fn encodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
174+
pub(super) fn encodable_generic_derive(
175+
mut s: synstructure::Structure<'_>,
176+
) -> proc_macro2::TokenStream {
165177
let encoder_ty = quote! { __E };
166178
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_serialize::Encoder });
167179
s.add_bounds(synstructure::AddBounds::Generics);

compiler/rustc_macros/src/symbols.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl Errors {
131131
}
132132
}
133133

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

137137
// If we generated any errors, then report them as compiler_error!() macro calls.

compiler/rustc_macros/src/type_foldable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use quote::{quote, ToTokens};
22
use syn::parse_quote;
33

4-
pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
4+
pub(super) fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
55
if let syn::Data::Union(_) = s.ast().data {
66
panic!("cannot derive on union")
77
}

compiler/rustc_macros/src/type_visitable.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use quote::quote;
22
use syn::parse_quote;
33

4-
pub fn type_visitable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
4+
pub(super) fn type_visitable_derive(
5+
mut s: synstructure::Structure<'_>,
6+
) -> proc_macro2::TokenStream {
57
if let syn::Data::Union(_) = s.ast().data {
68
panic!("cannot derive on union")
79
}

compiler/rustc_metadata/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![feature(proc_macro_internals)]
1717
#![feature(rustdoc_internals)]
1818
#![feature(trusted_len)]
19+
#![warn(unreachable_pub)]
1920
// tidy-alphabetical-end
2021

2122
extern crate proc_macro;

compiler/rustc_metadata/src/rmeta/decoder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ impl std::ops::Deref for MetadataBlob {
5656

5757
impl MetadataBlob {
5858
/// Runs the [`MemDecoder`] validation and if it passes, constructs a new [`MetadataBlob`].
59-
pub fn new(slice: OwnedSlice) -> Result<Self, ()> {
59+
pub(crate) fn new(slice: OwnedSlice) -> Result<Self, ()> {
6060
if MemDecoder::new(&slice, 0).is_ok() { Ok(Self(slice)) } else { Err(()) }
6161
}
6262

6363
/// Since this has passed the validation of [`MetadataBlob::new`], this returns bytes which are
6464
/// known to pass the [`MemDecoder`] validation.
65-
pub fn bytes(&self) -> &OwnedSlice {
65+
pub(crate) fn bytes(&self) -> &OwnedSlice {
6666
&self.0
6767
}
6868
}
@@ -332,12 +332,12 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
332332
}
333333

334334
#[inline]
335-
pub fn blob(&self) -> &'a MetadataBlob {
335+
pub(crate) fn blob(&self) -> &'a MetadataBlob {
336336
self.blob
337337
}
338338

339339
#[inline]
340-
pub fn cdata(&self) -> CrateMetadataRef<'a> {
340+
fn cdata(&self) -> CrateMetadataRef<'a> {
341341
debug_assert!(self.cdata.is_some(), "missing CrateMetadata in DecodeContext");
342342
self.cdata.unwrap()
343343
}
@@ -377,7 +377,7 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
377377
}
378378

379379
#[inline]
380-
pub fn read_raw_bytes(&mut self, len: usize) -> &[u8] {
380+
fn read_raw_bytes(&mut self, len: usize) -> &[u8] {
381381
self.opaque.read_raw_bytes(len)
382382
}
383383
}

compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ parameterized_over_tcx! {
1717

1818
impl DefPathHashMapRef<'_> {
1919
#[inline]
20-
pub fn def_path_hash_to_def_index(&self, def_path_hash: &DefPathHash) -> DefIndex {
20+
pub(crate) fn def_path_hash_to_def_index(&self, def_path_hash: &DefPathHash) -> DefIndex {
2121
match *self {
2222
DefPathHashMapRef::OwnedFromMetadata(ref map) => {
2323
map.get(&def_path_hash.local_hash()).unwrap()

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2309,7 +2309,7 @@ fn encode_root_position(mut file: &File, pos: usize) -> Result<(), std::io::Erro
23092309
Ok(())
23102310
}
23112311

2312-
pub fn provide(providers: &mut Providers) {
2312+
pub(crate) fn provide(providers: &mut Providers) {
23132313
*providers = Providers {
23142314
doc_link_resolutions: |tcx, def_id| {
23152315
tcx.resolutions(())

compiler/rustc_middle/src/dep_graph/dep_node.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalModDefId, ModDefId, LO
6161
use rustc_hir::definitions::DefPathHash;
6262
use rustc_hir::{HirId, ItemLocalId, OwnerId};
6363
pub use rustc_query_system::dep_graph::dep_node::DepKind;
64+
pub use rustc_query_system::dep_graph::DepNode;
6465
use rustc_query_system::dep_graph::FingerprintStyle;
65-
pub use rustc_query_system::dep_graph::{DepContext, DepNode, DepNodeParams};
66+
pub(crate) use rustc_query_system::dep_graph::{DepContext, DepNodeParams};
6667
use rustc_span::symbol::Symbol;
6768

6869
use crate::mir::mono::MonoItem;
@@ -101,7 +102,7 @@ macro_rules! define_dep_nodes {
101102

102103
// This checks that the discriminants of the variants have been assigned consecutively
103104
// from 0 so that they can be used as a dense index.
104-
pub const DEP_KIND_VARIANTS: u16 = {
105+
pub(crate) const DEP_KIND_VARIANTS: u16 = {
105106
let deps = &[$(dep_kinds::$variant,)*];
106107
let mut i = 0;
107108
while i < deps.len() {

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#![feature(try_blocks)]
6363
#![feature(type_alias_impl_trait)]
6464
#![feature(yeet_expr)]
65+
#![warn(unreachable_pub)]
6566
// tidy-alphabetical-end
6667

6768
#[cfg(test)]

compiler/rustc_middle/src/mir/basic_blocks.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ pub struct BasicBlocks<'tcx> {
1818
}
1919

2020
// Typically 95%+ of basic blocks have 4 or fewer predecessors.
21-
pub type Predecessors = IndexVec<BasicBlock, SmallVec<[BasicBlock; 4]>>;
21+
type Predecessors = IndexVec<BasicBlock, SmallVec<[BasicBlock; 4]>>;
2222

23-
pub type SwitchSources = FxHashMap<(BasicBlock, BasicBlock), SmallVec<[Option<u128>; 1]>>;
23+
type SwitchSources = FxHashMap<(BasicBlock, BasicBlock), SmallVec<[Option<u128>; 1]>>;
2424

2525
#[derive(Clone, Default, Debug)]
2626
struct Cache {

compiler/rustc_middle/src/mir/generic_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use gsgdt::{Edge, Graph, Node, NodeStyle};
22
use rustc_middle::mir::*;
33

44
/// Convert an MIR function into a gsgdt Graph
5-
pub fn mir_fn_to_generic_graph<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Graph {
5+
pub(crate) fn mir_fn_to_generic_graph<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Graph {
66
let def_id = body.source.def_id();
77
let def_name = graphviz_safe_def_name(def_id);
88
let graph_name = format!("Mir_{def_name}");

compiler/rustc_middle/src/mir/interpret/allocation/init_mask.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl hash::Hash for InitMaskMaterialized {
243243
}
244244

245245
impl InitMaskMaterialized {
246-
pub const BLOCK_SIZE: u64 = 64;
246+
const BLOCK_SIZE: u64 = 64;
247247

248248
fn new(size: Size, state: bool) -> Self {
249249
let mut m = InitMaskMaterialized { blocks: vec![] };

compiler/rustc_middle/src/mir/mono.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl<'tcx> CodegenUnit<'tcx> {
396396
// The codegen tests rely on items being process in the same order as
397397
// they appear in the file, so for local items, we sort by node_id first
398398
#[derive(PartialEq, Eq, PartialOrd, Ord)]
399-
pub struct ItemSortKey<'tcx>(Option<usize>, SymbolName<'tcx>);
399+
struct ItemSortKey<'tcx>(Option<usize>, SymbolName<'tcx>);
400400

401401
fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>) -> ItemSortKey<'tcx> {
402402
ItemSortKey(

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,7 @@ macro_rules! sty_debug_print {
21902190
all_infer: usize,
21912191
}
21922192

2193-
pub fn go(fmt: &mut std::fmt::Formatter<'_>, tcx: TyCtxt<'_>) -> std::fmt::Result {
2193+
pub(crate) fn go(fmt: &mut std::fmt::Formatter<'_>, tcx: TyCtxt<'_>) -> std::fmt::Result {
21942194
let mut total = DebugStat {
21952195
total: 0,
21962196
lt_infer: 0,

compiler/rustc_mir_build/src/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ impl UnsafeOpKind {
10271027
}
10281028
}
10291029

1030-
pub fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
1030+
pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
10311031
// Closures and inline consts are handled by their owner, if it has a body
10321032
// Also, don't safety check custom MIR
10331033
if tcx.is_typeck_child(def.to_def_id()) || tcx.has_attr(def, sym::custom_mir) {

compiler/rustc_mir_build/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(if_let_guard)]
99
#![feature(let_chains)]
1010
#![feature(try_blocks)]
11+
#![warn(unreachable_pub)]
1112
// tidy-alphabetical-end
1213

1314
mod build;

compiler/rustc_mir_dataflow/src/framework/engine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::errors::{
2424
};
2525
use crate::framework::BitSetExt;
2626

27-
pub type EntrySets<'tcx, A> = IndexVec<BasicBlock, <A as AnalysisDomain<'tcx>>::Domain>;
27+
type EntrySets<'tcx, A> = IndexVec<BasicBlock, <A as AnalysisDomain<'tcx>>::Domain>;
2828

2929
/// A dataflow analysis that has converged to fixpoint.
3030
#[derive(Clone)]

compiler/rustc_mir_dataflow/src/framework/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ impl<T: Idx> GenKill<T> for lattice::Dual<BitSet<T>> {
510510

511511
// NOTE: DO NOT CHANGE VARIANT ORDER. The derived `Ord` impls rely on the current order.
512512
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
513-
pub enum Effect {
513+
enum Effect {
514514
/// The "before" effect (e.g., `apply_before_statement_effect`) for a statement (or
515515
/// terminator).
516516
Before,
@@ -520,7 +520,7 @@ pub enum Effect {
520520
}
521521

522522
impl Effect {
523-
pub const fn at_index(self, statement_index: usize) -> EffectIndex {
523+
const fn at_index(self, statement_index: usize) -> EffectIndex {
524524
EffectIndex { effect: self, statement_index }
525525
}
526526
}

compiler/rustc_mir_dataflow/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![feature(exact_size_is_empty)]
66
#![feature(let_chains)]
77
#![feature(try_blocks)]
8+
#![warn(unreachable_pub)]
89
// tidy-alphabetical-end
910

1011
use rustc_middle::ty;

compiler/rustc_mir_dataflow/src/move_paths/abs_domain.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ use rustc_middle::mir::{Local, Operand, PlaceElem, ProjectionElem};
1515
use rustc_middle::ty::Ty;
1616

1717
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
18-
pub struct AbstractOperand;
18+
pub(crate) struct AbstractOperand;
1919
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
20-
pub struct AbstractType;
21-
pub type AbstractElem = ProjectionElem<AbstractOperand, AbstractType>;
20+
pub(crate) struct AbstractType;
21+
pub(crate) type AbstractElem = ProjectionElem<AbstractOperand, AbstractType>;
2222

23-
pub trait Lift {
23+
pub(crate) trait Lift {
2424
type Abstract;
2525
fn lift(&self) -> Self::Abstract;
2626
}

0 commit comments

Comments
 (0)