Skip to content

Commit 3759fd7

Browse files
committed
Enable type privacy lints in rustc
1 parent 320b412 commit 3759fd7

File tree

41 files changed

+136
-22
lines changed

Some content is hidden

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

41 files changed

+136
-22
lines changed

compiler/rustc_privacy/src/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> {
19391939
let reexported_at_vis = effective_vis.at_level(Level::Reexported);
19401940
let reachable_at_vis = effective_vis.at_level(Level::Reachable);
19411941

1942-
if reexported_at_vis != reachable_at_vis {
1942+
if reachable_at_vis.is_public() && reexported_at_vis != reachable_at_vis {
19431943
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
19441944
let span = self.tcx.def_span(def_id.to_def_id());
19451945
self.tcx.emit_spanned_lint(
@@ -1971,10 +1971,6 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> {
19711971
AssocItemKind::Type => (self.tcx.defaultness(def_id).has_value(), true),
19721972
};
19731973

1974-
if is_assoc_ty {
1975-
self.check_unnameable(def_id, self.get(def_id));
1976-
}
1977-
19781974
check.in_assoc_ty = is_assoc_ty;
19791975
check.generics().predicates();
19801976
if check_ty {

library/alloc/src/slice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ pub(crate) mod hack {
111111
T::to_vec(s, alloc)
112112
}
113113

114+
#[allow(unnameable_types)]
115+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
114116
#[cfg(not(no_global_oom_handling))]
115117
pub trait ConvertVec {
116118
fn to_vec<A: Allocator>(s: &[Self], alloc: A) -> Vec<Self, A>

library/alloc/src/vec/into_iter.rs

+2
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ where
360360
}
361361
}
362362

363+
#[allow(unnameable_types)]
364+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(vec)`
363365
#[doc(hidden)]
364366
#[unstable(issue = "none", feature = "std_internals")]
365367
#[rustc_unsafe_specialization_marker]

library/core/src/array/drain.rs

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub(crate) fn drain_array_with<T, R, const N: usize>(
2929
/// See [`drain_array_with`] -- this is `pub(crate)` only so it's allowed to be
3030
/// mentioned in the signature of that method. (Otherwise it hits `E0446`.)
3131
// INVARIANT: It's ok to drop the remainder of the inner iterator.
32+
#[cfg_attr(bootstrap, allow(unnameable_types))]
33+
//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(array)`
3234
pub(crate) struct Drain<'a, T>(slice::IterMut<'a, T>);
3335

3436
impl<T> Drop for Drain<'_, T> {
@@ -39,6 +41,8 @@ impl<T> Drop for Drain<'_, T> {
3941
}
4042

4143
impl<T> Iterator for Drain<'_, T> {
44+
#[cfg_attr(bootstrap, allow(unnameable_types))]
45+
//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(array)`
4246
type Item = T;
4347

4448
#[inline]

library/core/src/convert/num.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ mod private {
55
/// This trait being unreachable from outside the crate
66
/// prevents other implementations of the `FloatToInt` trait,
77
/// which allows potentially adding more trait methods after the trait is `#[stable]`.
8+
#[allow(unnameable_types)]
9+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(num)`
810
#[unstable(feature = "convert_float_to_int", issue = "67057")]
911
pub trait Sealed {}
1012
}

library/core/src/error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ where
207207
mod private {
208208
// This is a hack to prevent `type_id` from being overridden by `Error`
209209
// implementations, since that can enable unsound downcasting.
210+
#[allow(unnameable_types)]
211+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(error)`
210212
#[unstable(feature = "error_type_id", issue = "60784")]
211213
#[derive(Debug)]
212214
pub struct Internal;

library/core/src/ffi/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ impl<'a, 'f: 'a> DerefMut for VaList<'a, 'f> {
522522
// improving this.
523523
mod sealed_trait {
524524
/// Trait which permits the allowed types to be used with [super::VaListImpl::arg].
525+
#[allow(unnameable_types)]
526+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(ffi)`
525527
#[unstable(
526528
feature = "c_variadic",
527529
reason = "the `c_variadic` feature has not been properly tested on \

library/core/src/fmt/rt.rs

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
66
use super::*;
77

8+
#[allow(unnameable_types)]
9+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(fmt)`
810
#[lang = "format_placeholder"]
911
#[derive(Copy, Clone)]
1012
pub struct Placeholder {
@@ -30,6 +32,8 @@ impl Placeholder {
3032
}
3133
}
3234

35+
#[allow(unnameable_types)]
36+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(fmt)`
3337
#[lang = "format_alignment"]
3438
#[derive(Copy, Clone, PartialEq, Eq)]
3539
pub enum Alignment {
@@ -41,6 +45,8 @@ pub enum Alignment {
4145

4246
/// Used by [width](https://doc.rust-lang.org/std/fmt/#width)
4347
/// and [precision](https://doc.rust-lang.org/std/fmt/#precision) specifiers.
48+
#[allow(unnameable_types)]
49+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(fmt)`
4450
#[lang = "format_count"]
4551
#[derive(Copy, Clone)]
4652
pub enum Count {
@@ -70,6 +76,8 @@ pub(super) enum Flag {
7076
///
7177
/// Argument is essentially an optimized partially applied formatting function,
7278
/// equivalent to `exists T.(&T, fn(&T, &mut Formatter<'_>) -> Result`.
79+
#[allow(unnameable_types)]
80+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(fmt)`
7381
#[lang = "format_argument"]
7482
#[derive(Copy, Clone)]
7583
pub struct Argument<'a> {
@@ -172,6 +180,8 @@ impl<'a> Argument<'a> {
172180
/// This struct represents the unsafety of constructing an `Arguments`.
173181
/// It exists, rather than an unsafe function, in order to simplify the expansion
174182
/// of `format_args!(..)` and reduce the scope of the `unsafe` block.
183+
#[allow(unnameable_types)]
184+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(fmt)`
175185
#[lang = "format_unsafe_arg"]
176186
pub struct UnsafeArg {
177187
_private: (),

library/core/src/future/join.rs

+4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ macro join_internal {
149149
/// be later taken and doesn't panic when polled after ready.
150150
///
151151
/// This type is public in a private module for use by the macro.
152+
#[allow(unnameable_types)]
153+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(future)`
152154
#[allow(missing_debug_implementations)]
153155
#[unstable(feature = "future_join", issue = "91642")]
154156
pub enum MaybeDone<F: Future> {
@@ -172,6 +174,8 @@ impl<F: Future> MaybeDone<F> {
172174

173175
#[unstable(feature = "future_join", issue = "91642")]
174176
impl<F: Future> Future for MaybeDone<F> {
177+
#[cfg_attr(bootstrap, allow(unnameable_types))]
178+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(future)`
175179
type Output = ();
176180

177181
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {

library/core/src/iter/adapters/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ pub unsafe trait SourceIter {
145145
///
146146
/// If a `ControlFlow::Break` is encountered, the iterator stops and the
147147
/// residual is stored.
148+
#[cfg_attr(bootstrap, allow(unnameable_types))]
149+
//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(iter)`
148150
pub(crate) struct GenericShunt<'a, I, R> {
149151
iter: I,
150152
residual: &'a mut Option<R>,
@@ -172,6 +174,8 @@ impl<I, R> Iterator for GenericShunt<'_, I, R>
172174
where
173175
I: Iterator<Item: Try<Residual = R>>,
174176
{
177+
#[cfg_attr(bootstrap, allow(unnameable_types))]
178+
//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(iter)`
175179
type Item = <I::Item as Try>::Output;
176180

177181
fn next(&mut self) -> Option<Self::Item> {
@@ -211,6 +215,8 @@ unsafe impl<I, R> SourceIter for GenericShunt<'_, I, R>
211215
where
212216
I: SourceIter,
213217
{
218+
#[cfg_attr(bootstrap, allow(unnameable_types))]
219+
//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(iter)`
214220
type Source = I::Source;
215221

216222
#[inline]

library/core/src/iter/sources/from_generator.rs

+4
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ pub fn from_generator<G: Generator<Return = ()> + Unpin>(generator: G) -> FromGe
3434
/// more.
3535
///
3636
/// [`iter::from_generator()`]: from_generator
37+
#[allow(unnameable_types)]
38+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(sources)`
3739
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
3840
#[derive(Clone)]
3941
pub struct FromGenerator<G>(G);
4042

4143
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
4244
impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> {
45+
#[cfg_attr(bootstrap, allow(unnameable_types))]
46+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(sources)`
4347
type Item = G::Yield;
4448

4549
fn next(&mut self) -> Option<Self::Item> {

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ pub mod primitive;
397397
missing_docs,
398398
missing_debug_implementations,
399399
dead_code,
400+
unnameable_types,
400401
unused_imports,
401402
unsafe_op_in_unsafe_fn
402403
)]

library/core/src/num/dec2flt/common.rs

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pub(crate) fn is_8digits(v: u64) -> bool {
6565

6666
/// A custom 64-bit floating point type, representing `f * 2^e`.
6767
/// e is biased, so it be directly shifted into the exponent bits.
68+
#[allow(unnameable_types)]
69+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(dec2flt)`
6870
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
6971
pub struct BiasedFp {
7072
/// The significant digits.

library/core/src/ops/try_trait.rs

+4
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ impl<T> NeverShortCircuit<T> {
418418
}
419419
}
420420

421+
#[cfg_attr(bootstrap, allow(unnameable_types))]
422+
//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(ops)`
421423
pub(crate) enum NeverShortCircuitResidual {}
422424

423425
impl<T> Try for NeverShortCircuit<T> {
@@ -443,6 +445,8 @@ impl<T> FromResidual for NeverShortCircuit<T> {
443445
}
444446

445447
impl<T> Residual<T> for NeverShortCircuitResidual {
448+
#[cfg_attr(bootstrap, allow(unnameable_types))]
449+
//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(ops)`
446450
type TryType = NeverShortCircuit<T>;
447451
}
448452

library/core/src/slice/index.rs

+2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ const fn slice_end_index_overflow_fail() -> ! {
120120

121121
mod private_slice_index {
122122
use super::ops;
123+
#[allow(unnameable_types)]
124+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(index)`
123125
#[stable(feature = "slice_get_slice", since = "1.28.0")]
124126
pub trait Sealed {}
125127

library/core/src/str/lossy.rs

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ impl<'a> Utf8Chunk<'a> {
6969
}
7070
}
7171

72+
#[allow(unnameable_types)]
73+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(str)`
7274
#[must_use]
7375
#[unstable(feature = "str_internals", issue = "none")]
7476
pub struct Debug<'a>(&'a [u8]);

library/portable-simd/crates/core_simd/src/cast.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ mod sealed {
66
/// # Safety
77
/// Implementing this trait asserts that the type is a valid vector element for the `simd_cast`
88
/// or `simd_as` intrinsics.
9+
#[allow(unnameable_types)]
10+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(cast)`
911
pub unsafe trait Sealed {}
1012
}
1113
use sealed::Sealed;

library/portable-simd/crates/core_simd/src/elements.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ mod mut_ptr;
55
mod uint;
66

77
mod sealed {
8+
#[allow(unnameable_types)]
9+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(elements)`
810
pub trait Sealed {}
911
}
1012

library/portable-simd/crates/core_simd/src/lane_count.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
mod sealed {
2+
#[allow(unnameable_types)]
3+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(lane_count)`
24
pub trait Sealed {}
35
}
46
use sealed::Sealed;

library/portable-simd/crates/core_simd/src/masks.rs

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ mod sealed {
3131
/// For example, `eq` could be provided by requiring `MaskElement: PartialEq`, but that would
3232
/// prevent us from ever removing that bound, or from implementing `MaskElement` on
3333
/// non-`PartialEq` types in the future.
34+
#[allow(unnameable_types)]
35+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(vector)`
3436
pub trait Sealed {
3537
fn valid<const LANES: usize>(values: Simd<Self, LANES>) -> bool
3638
where

library/portable-simd/crates/core_simd/src/masks/full_masks.rs

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::simd::{LaneCount, Simd, SupportedLaneCount, ToBitMask};
77
#[cfg(feature = "generic_const_exprs")]
88
use crate::simd::ToBitMaskArray;
99

10+
#[allow(unnameable_types)]
11+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)`
1012
#[repr(transparent)]
1113
pub struct Mask<T, const LANES: usize>(Simd<T, LANES>)
1214
where
@@ -73,6 +75,8 @@ where
7375
}
7476

7577
// Used for bitmask bit order workaround
78+
#[cfg_attr(bootstrap, allow(unnameable_types))]
79+
//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(masks)`
7680
pub(crate) trait ReverseBits {
7781
// Reverse the least significant `n` bits of `self`.
7882
// (Remaining bits must be 0.)
@@ -276,6 +280,8 @@ where
276280
T: MaskElement,
277281
LaneCount<LANES>: SupportedLaneCount,
278282
{
283+
#[cfg_attr(bootstrap, allow(unnameable_types))]
284+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)`
279285
type Output = Self;
280286
#[inline]
281287
#[must_use = "method returns a new mask and does not mutate the original value"]
@@ -290,6 +296,8 @@ where
290296
T: MaskElement,
291297
LaneCount<LANES>: SupportedLaneCount,
292298
{
299+
#[cfg_attr(bootstrap, allow(unnameable_types))]
300+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)`
293301
type Output = Self;
294302
#[inline]
295303
#[must_use = "method returns a new mask and does not mutate the original value"]
@@ -304,6 +312,8 @@ where
304312
T: MaskElement,
305313
LaneCount<LANES>: SupportedLaneCount,
306314
{
315+
#[cfg_attr(bootstrap, allow(unnameable_types))]
316+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)`
307317
type Output = Self;
308318
#[inline]
309319
#[must_use = "method returns a new mask and does not mutate the original value"]
@@ -318,6 +328,8 @@ where
318328
T: MaskElement,
319329
LaneCount<LANES>: SupportedLaneCount,
320330
{
331+
#[cfg_attr(bootstrap, allow(unnameable_types))]
332+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)`
321333
type Output = Self;
322334
#[inline]
323335
#[must_use = "method returns a new mask and does not mutate the original value"]

library/portable-simd/crates/core_simd/src/masks/to_bitmask.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use super::{mask_impl, Mask, MaskElement};
22
use crate::simd::{LaneCount, SupportedLaneCount};
33

44
mod sealed {
5+
#[allow(unnameable_types)]
6+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)`
57
pub trait Sealed {}
68
}
79
pub use sealed::Sealed;

library/portable-simd/crates/core_simd/src/vector.rs

+2
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,8 @@ where
848848
}
849849

850850
mod sealed {
851+
#[allow(unnameable_types)]
852+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(vector)`
851853
pub trait Sealed {}
852854
}
853855
use sealed::Sealed;

library/proc_macro/src/bridge/buffer.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use std::ops::{Deref, DerefMut};
66
use std::slice;
77

88
#[repr(C)]
9+
#[allow(unnameable_types)]
10+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(bridge)`
911
pub struct Buffer {
1012
data: *mut u8,
1113
len: usize,
@@ -25,6 +27,8 @@ impl Default for Buffer {
2527
}
2628

2729
impl Deref for Buffer {
30+
#[cfg_attr(bootstrap, allow(unnameable_types))]
31+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(bridge)`
2832
type Target = [u8];
2933
#[inline]
3034
fn deref(&self) -> &[u8] {

library/proc_macro/src/bridge/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use std::str;
1616
use super::*;
1717

1818
/// Handle for a symbol string stored within the Interner.
19+
#[allow(unnameable_types)]
20+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
1921
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
2022
pub struct Symbol(NonZeroU32);
2123

library/proc_macro/src/diagnostic.rs

+4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ macro_rules! diagnostic_child_methods {
7979
}
8080

8181
/// Iterator over the children diagnostics of a `Diagnostic`.
82+
#[allow(unnameable_types)]
83+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
8284
#[derive(Debug, Clone)]
8385
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
8486
pub struct Children<'a>(std::slice::Iter<'a, Diagnostic>);
8587

88+
#[allow(unnameable_types)]
89+
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
8690
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
8791
impl<'a> Iterator for Children<'a> {
8892
type Item = &'a Diagnostic;

library/std/src/io/error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ pub type RawOsError = i32;
118118
// (For the sake of being explicit: the alignment requirement here only matters
119119
// if `error/repr_bitpacked.rs` is in use — for the unpacked repr it doesn't
120120
// matter at all)
121+
#[cfg_attr(bootstrap, allow(unnameable_types))]
122+
//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(io)`
121123
#[repr(align(4))]
122124
#[derive(Debug)]
123125
pub(crate) struct SimpleMessage {

0 commit comments

Comments
 (0)