Skip to content

Commit 7e23a44

Browse files
Rollup merge of rust-lang#129732 - nnethercote:unreachable_pub-3, r=Urgau
Add `unreachable_pub`, round 3 A follow-up to rust-lang#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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 20 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 5 deletions
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
}

0 commit comments

Comments
 (0)