diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index fe23506b878dc..93b5378145fcb 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -1939,7 +1939,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> { let reexported_at_vis = effective_vis.at_level(Level::Reexported); let reachable_at_vis = effective_vis.at_level(Level::Reachable); - if reexported_at_vis != reachable_at_vis { + if reachable_at_vis.is_public() && reexported_at_vis != reachable_at_vis { let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); let span = self.tcx.def_span(def_id.to_def_id()); self.tcx.emit_spanned_lint( @@ -1971,10 +1971,6 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> { AssocItemKind::Type => (self.tcx.defaultness(def_id).has_value(), true), }; - if is_assoc_ty { - self.check_unnameable(def_id, self.get(def_id)); - } - check.in_assoc_ty = is_assoc_ty; check.generics().predicates(); if check_ty { diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 093dcbbe8bf77..499a825f2ff6f 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -111,6 +111,8 @@ pub(crate) mod hack { T::to_vec(s, alloc) } + #[allow(unnameable_types)] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[cfg(not(no_global_oom_handling))] pub trait ConvertVec { fn to_vec(s: &[Self], alloc: A) -> Vec diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index b2db2fdfd18f1..0ac3a2aa0459d 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -360,6 +360,8 @@ where } } +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(vec)` #[doc(hidden)] #[unstable(issue = "none", feature = "std_internals")] #[rustc_unsafe_specialization_marker] diff --git a/library/core/src/array/drain.rs b/library/core/src/array/drain.rs index 5fadf907b6219..5a803d6469406 100644 --- a/library/core/src/array/drain.rs +++ b/library/core/src/array/drain.rs @@ -29,6 +29,8 @@ pub(crate) fn drain_array_with( /// See [`drain_array_with`] -- this is `pub(crate)` only so it's allowed to be /// mentioned in the signature of that method. (Otherwise it hits `E0446`.) // INVARIANT: It's ok to drop the remainder of the inner iterator. +#[cfg_attr(bootstrap, allow(unnameable_types))] +//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(array)` pub(crate) struct Drain<'a, T>(slice::IterMut<'a, T>); impl Drop for Drain<'_, T> { @@ -39,6 +41,8 @@ impl Drop for Drain<'_, T> { } impl Iterator for Drain<'_, T> { + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(array)` type Item = T; #[inline] diff --git a/library/core/src/convert/num.rs b/library/core/src/convert/num.rs index 56ab63be27d37..40e4ef7e386ad 100644 --- a/library/core/src/convert/num.rs +++ b/library/core/src/convert/num.rs @@ -5,6 +5,8 @@ mod private { /// This trait being unreachable from outside the crate /// prevents other implementations of the `FloatToInt` trait, /// which allows potentially adding more trait methods after the trait is `#[stable]`. + #[allow(unnameable_types)] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(num)` #[unstable(feature = "convert_float_to_int", issue = "67057")] pub trait Sealed {} } diff --git a/library/core/src/error.rs b/library/core/src/error.rs index 11cb082757864..76aad12e4c284 100644 --- a/library/core/src/error.rs +++ b/library/core/src/error.rs @@ -207,6 +207,8 @@ where mod private { // This is a hack to prevent `type_id` from being overridden by `Error` // implementations, since that can enable unsound downcasting. + #[allow(unnameable_types)] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(error)` #[unstable(feature = "error_type_id", issue = "60784")] #[derive(Debug)] pub struct Internal; diff --git a/library/core/src/ffi/mod.rs b/library/core/src/ffi/mod.rs index 0488c807604d3..5640790fccbfe 100644 --- a/library/core/src/ffi/mod.rs +++ b/library/core/src/ffi/mod.rs @@ -522,6 +522,8 @@ impl<'a, 'f: 'a> DerefMut for VaList<'a, 'f> { // improving this. mod sealed_trait { /// Trait which permits the allowed types to be used with [super::VaListImpl::arg]. + #[allow(unnameable_types)] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(ffi)` #[unstable( feature = "c_variadic", reason = "the `c_variadic` feature has not been properly tested on \ diff --git a/library/core/src/fmt/rt.rs b/library/core/src/fmt/rt.rs index d37888c27bde3..b95fabce6a52f 100644 --- a/library/core/src/fmt/rt.rs +++ b/library/core/src/fmt/rt.rs @@ -5,6 +5,8 @@ use super::*; +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(fmt)` #[lang = "format_placeholder"] #[derive(Copy, Clone)] pub struct Placeholder { @@ -30,6 +32,8 @@ impl Placeholder { } } +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(fmt)` #[lang = "format_alignment"] #[derive(Copy, Clone, PartialEq, Eq)] pub enum Alignment { @@ -41,6 +45,8 @@ pub enum Alignment { /// Used by [width](https://doc.rust-lang.org/std/fmt/#width) /// and [precision](https://doc.rust-lang.org/std/fmt/#precision) specifiers. +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(fmt)` #[lang = "format_count"] #[derive(Copy, Clone)] pub enum Count { @@ -70,6 +76,8 @@ pub(super) enum Flag { /// /// Argument is essentially an optimized partially applied formatting function, /// equivalent to `exists T.(&T, fn(&T, &mut Formatter<'_>) -> Result`. +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(fmt)` #[lang = "format_argument"] #[derive(Copy, Clone)] pub struct Argument<'a> { @@ -172,6 +180,8 @@ impl<'a> Argument<'a> { /// This struct represents the unsafety of constructing an `Arguments`. /// It exists, rather than an unsafe function, in order to simplify the expansion /// of `format_args!(..)` and reduce the scope of the `unsafe` block. +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(fmt)` #[lang = "format_unsafe_arg"] pub struct UnsafeArg { _private: (), diff --git a/library/core/src/future/join.rs b/library/core/src/future/join.rs index 3f35179ddc29b..088b5bf07a1c1 100644 --- a/library/core/src/future/join.rs +++ b/library/core/src/future/join.rs @@ -149,6 +149,8 @@ macro join_internal { /// be later taken and doesn't panic when polled after ready. /// /// This type is public in a private module for use by the macro. +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(future)` #[allow(missing_debug_implementations)] #[unstable(feature = "future_join", issue = "91642")] pub enum MaybeDone { @@ -172,6 +174,8 @@ impl MaybeDone { #[unstable(feature = "future_join", issue = "91642")] impl Future for MaybeDone { + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(future)` type Output = (); fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { diff --git a/library/core/src/iter/adapters/mod.rs b/library/core/src/iter/adapters/mod.rs index 8cc2b7cec4165..d9cb2c16c1f25 100644 --- a/library/core/src/iter/adapters/mod.rs +++ b/library/core/src/iter/adapters/mod.rs @@ -145,6 +145,8 @@ pub unsafe trait SourceIter { /// /// If a `ControlFlow::Break` is encountered, the iterator stops and the /// residual is stored. +#[cfg_attr(bootstrap, allow(unnameable_types))] +//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(iter)` pub(crate) struct GenericShunt<'a, I, R> { iter: I, residual: &'a mut Option, @@ -172,6 +174,8 @@ impl Iterator for GenericShunt<'_, I, R> where I: Iterator>, { + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(iter)` type Item = ::Output; fn next(&mut self) -> Option { @@ -211,6 +215,8 @@ unsafe impl SourceIter for GenericShunt<'_, I, R> where I: SourceIter, { + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(iter)` type Source = I::Source; #[inline] diff --git a/library/core/src/iter/sources/from_generator.rs b/library/core/src/iter/sources/from_generator.rs index 4cbe731b222f9..09ade2d7d31dd 100644 --- a/library/core/src/iter/sources/from_generator.rs +++ b/library/core/src/iter/sources/from_generator.rs @@ -34,12 +34,16 @@ pub fn from_generator + Unpin>(generator: G) -> FromGe /// more. /// /// [`iter::from_generator()`]: from_generator +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(sources)` #[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")] #[derive(Clone)] pub struct FromGenerator(G); #[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")] impl + Unpin> Iterator for FromGenerator { + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(sources)` type Item = G::Yield; fn next(&mut self) -> Option { diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 05876f5fc581b..82f2c6809cba4 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -397,6 +397,7 @@ pub mod primitive; missing_docs, missing_debug_implementations, dead_code, + unnameable_types, unused_imports, unsafe_op_in_unsafe_fn )] diff --git a/library/core/src/num/dec2flt/common.rs b/library/core/src/num/dec2flt/common.rs index 11a626485191c..b05ab50205c08 100644 --- a/library/core/src/num/dec2flt/common.rs +++ b/library/core/src/num/dec2flt/common.rs @@ -65,6 +65,8 @@ pub(crate) fn is_8digits(v: u64) -> bool { /// A custom 64-bit floating point type, representing `f * 2^e`. /// e is biased, so it be directly shifted into the exponent bits. +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(dec2flt)` #[derive(Debug, Copy, Clone, PartialEq, Eq, Default)] pub struct BiasedFp { /// The significant digits. diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs index 17625daccbcf9..6e063fbd09092 100644 --- a/library/core/src/ops/try_trait.rs +++ b/library/core/src/ops/try_trait.rs @@ -418,6 +418,8 @@ impl NeverShortCircuit { } } +#[cfg_attr(bootstrap, allow(unnameable_types))] +//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(ops)` pub(crate) enum NeverShortCircuitResidual {} impl Try for NeverShortCircuit { @@ -443,6 +445,8 @@ impl FromResidual for NeverShortCircuit { } impl Residual for NeverShortCircuitResidual { + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(ops)` type TryType = NeverShortCircuit; } diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index e1e3bcc05e74b..1d90f312943e1 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -120,6 +120,8 @@ const fn slice_end_index_overflow_fail() -> ! { mod private_slice_index { use super::ops; + #[allow(unnameable_types)] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(index)` #[stable(feature = "slice_get_slice", since = "1.28.0")] pub trait Sealed {} diff --git a/library/core/src/str/lossy.rs b/library/core/src/str/lossy.rs index 59f873d1268ce..f2aed0373b5c1 100644 --- a/library/core/src/str/lossy.rs +++ b/library/core/src/str/lossy.rs @@ -69,6 +69,8 @@ impl<'a> Utf8Chunk<'a> { } } +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(str)` #[must_use] #[unstable(feature = "str_internals", issue = "none")] pub struct Debug<'a>(&'a [u8]); diff --git a/library/portable-simd/crates/core_simd/src/cast.rs b/library/portable-simd/crates/core_simd/src/cast.rs index 1c3592f807578..3c9fbde729689 100644 --- a/library/portable-simd/crates/core_simd/src/cast.rs +++ b/library/portable-simd/crates/core_simd/src/cast.rs @@ -6,6 +6,8 @@ mod sealed { /// # Safety /// Implementing this trait asserts that the type is a valid vector element for the `simd_cast` /// or `simd_as` intrinsics. + #[allow(unnameable_types)] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(cast)` pub unsafe trait Sealed {} } use sealed::Sealed; diff --git a/library/portable-simd/crates/core_simd/src/elements.rs b/library/portable-simd/crates/core_simd/src/elements.rs index dc7f52a4d576c..a470aab323503 100644 --- a/library/portable-simd/crates/core_simd/src/elements.rs +++ b/library/portable-simd/crates/core_simd/src/elements.rs @@ -5,6 +5,8 @@ mod mut_ptr; mod uint; mod sealed { + #[allow(unnameable_types)] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(elements)` pub trait Sealed {} } diff --git a/library/portable-simd/crates/core_simd/src/lane_count.rs b/library/portable-simd/crates/core_simd/src/lane_count.rs index 2b91eb9e80047..e91f935e8afbe 100644 --- a/library/portable-simd/crates/core_simd/src/lane_count.rs +++ b/library/portable-simd/crates/core_simd/src/lane_count.rs @@ -1,4 +1,6 @@ mod sealed { + #[allow(unnameable_types)] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(lane_count)` pub trait Sealed {} } use sealed::Sealed; diff --git a/library/portable-simd/crates/core_simd/src/masks.rs b/library/portable-simd/crates/core_simd/src/masks.rs index fea687bdc1aef..beca9dc8b6ef3 100644 --- a/library/portable-simd/crates/core_simd/src/masks.rs +++ b/library/portable-simd/crates/core_simd/src/masks.rs @@ -31,6 +31,8 @@ mod sealed { /// For example, `eq` could be provided by requiring `MaskElement: PartialEq`, but that would /// prevent us from ever removing that bound, or from implementing `MaskElement` on /// non-`PartialEq` types in the future. + #[allow(unnameable_types)] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(vector)` pub trait Sealed { fn valid(values: Simd) -> bool where diff --git a/library/portable-simd/crates/core_simd/src/masks/full_masks.rs b/library/portable-simd/crates/core_simd/src/masks/full_masks.rs index 1d13c45b8e70b..3a1dab143d93c 100644 --- a/library/portable-simd/crates/core_simd/src/masks/full_masks.rs +++ b/library/portable-simd/crates/core_simd/src/masks/full_masks.rs @@ -7,6 +7,8 @@ use crate::simd::{LaneCount, Simd, SupportedLaneCount, ToBitMask}; #[cfg(feature = "generic_const_exprs")] use crate::simd::ToBitMaskArray; +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)` #[repr(transparent)] pub struct Mask(Simd) where @@ -73,6 +75,8 @@ where } // Used for bitmask bit order workaround +#[cfg_attr(bootstrap, allow(unnameable_types))] +//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(masks)` pub(crate) trait ReverseBits { // Reverse the least significant `n` bits of `self`. // (Remaining bits must be 0.) @@ -276,6 +280,8 @@ where T: MaskElement, LaneCount: SupportedLaneCount, { + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)` type Output = Self; #[inline] #[must_use = "method returns a new mask and does not mutate the original value"] @@ -290,6 +296,8 @@ where T: MaskElement, LaneCount: SupportedLaneCount, { + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)` type Output = Self; #[inline] #[must_use = "method returns a new mask and does not mutate the original value"] @@ -304,6 +312,8 @@ where T: MaskElement, LaneCount: SupportedLaneCount, { + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)` type Output = Self; #[inline] #[must_use = "method returns a new mask and does not mutate the original value"] @@ -318,6 +328,8 @@ where T: MaskElement, LaneCount: SupportedLaneCount, { + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)` type Output = Self; #[inline] #[must_use = "method returns a new mask and does not mutate the original value"] diff --git a/library/portable-simd/crates/core_simd/src/masks/to_bitmask.rs b/library/portable-simd/crates/core_simd/src/masks/to_bitmask.rs index fc7d6b781f2f5..231eb255c98f2 100644 --- a/library/portable-simd/crates/core_simd/src/masks/to_bitmask.rs +++ b/library/portable-simd/crates/core_simd/src/masks/to_bitmask.rs @@ -2,6 +2,8 @@ use super::{mask_impl, Mask, MaskElement}; use crate::simd::{LaneCount, SupportedLaneCount}; mod sealed { + #[allow(unnameable_types)] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(masks)` pub trait Sealed {} } pub use sealed::Sealed; diff --git a/library/portable-simd/crates/core_simd/src/vector.rs b/library/portable-simd/crates/core_simd/src/vector.rs index 9aa7bacfce981..0c17852fb08b9 100644 --- a/library/portable-simd/crates/core_simd/src/vector.rs +++ b/library/portable-simd/crates/core_simd/src/vector.rs @@ -848,6 +848,8 @@ where } mod sealed { + #[allow(unnameable_types)] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(vector)` pub trait Sealed {} } use sealed::Sealed; diff --git a/library/proc_macro/src/bridge/buffer.rs b/library/proc_macro/src/bridge/buffer.rs index 48030f8d82dca..f637dcba34815 100644 --- a/library/proc_macro/src/bridge/buffer.rs +++ b/library/proc_macro/src/bridge/buffer.rs @@ -6,6 +6,8 @@ use std::ops::{Deref, DerefMut}; use std::slice; #[repr(C)] +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(bridge)` pub struct Buffer { data: *mut u8, len: usize, @@ -25,6 +27,8 @@ impl Default for Buffer { } impl Deref for Buffer { + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub`, but can only be named at visibility `pub(bridge)` type Target = [u8]; #[inline] fn deref(&self) -> &[u8] { diff --git a/library/proc_macro/src/bridge/symbol.rs b/library/proc_macro/src/bridge/symbol.rs index 930c111455df0..87a1e1722a4fb 100644 --- a/library/proc_macro/src/bridge/symbol.rs +++ b/library/proc_macro/src/bridge/symbol.rs @@ -16,6 +16,8 @@ use std::str; use super::*; /// Handle for a symbol string stored within the Interner. +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[derive(Copy, Clone, PartialEq, Eq, Hash)] pub struct Symbol(NonZeroU32); diff --git a/library/proc_macro/src/diagnostic.rs b/library/proc_macro/src/diagnostic.rs index 5a209f7c7aa18..795bcb21ec44d 100644 --- a/library/proc_macro/src/diagnostic.rs +++ b/library/proc_macro/src/diagnostic.rs @@ -79,10 +79,14 @@ macro_rules! diagnostic_child_methods { } /// Iterator over the children diagnostics of a `Diagnostic`. +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[derive(Debug, Clone)] #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] pub struct Children<'a>(std::slice::Iter<'a, Diagnostic>); +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] impl<'a> Iterator for Children<'a> { type Item = &'a Diagnostic; diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 34c0ce9dcf848..0971e7eb3db24 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -118,6 +118,8 @@ pub type RawOsError = i32; // (For the sake of being explicit: the alignment requirement here only matters // if `error/repr_bitpacked.rs` is in use — for the unpacked repr it doesn't // matter at all) +#[cfg_attr(bootstrap, allow(unnameable_types))] +//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(io)` #[repr(align(4))] #[derive(Debug)] pub(crate) struct SimpleMessage { diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index d287397aab3a3..ff1d0a17c7e14 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -655,6 +655,7 @@ mod sealed { /// This trait being unreachable from outside the crate /// prevents outside implementations of our extension traits. /// This allows adding more trait methods in the future. + #[allow(unnameable_types)] #[unstable(feature = "sealed", issue = "none")] pub trait Sealed {} } diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index 85e020ae41328..a87bfd241a748 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -24,6 +24,8 @@ use libc::off64_t; )))] use libc::off_t as off64_t; +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[derive(Debug)] pub struct FileDesc(OwnedFd); diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 640648e870748..2666767c349a9 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -127,12 +127,16 @@ pub struct StdioPipes { // passed to do_exec() with configuration of what the child stdio should look // like +#[cfg_attr(bootstrap, allow(unnameable_types))] +//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(process)` pub struct ChildPipes { pub stdin: ChildStdio, pub stdout: ChildStdio, pub stderr: ChildStdio, } +#[cfg_attr(bootstrap, allow(unnameable_types))] +//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(process)` pub enum ChildStdio { Inherit, Explicit(c_int), @@ -152,6 +156,8 @@ pub enum Stdio { Fd(FileDesc), } +#[cfg_attr(bootstrap, allow(unnameable_types))] +//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(process)` #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum ProgramKind { /// A program that would be looked up on the PATH (e.g. `ls`) @@ -399,6 +405,8 @@ fn os2c(s: &OsStr, saw_nul: &mut bool) -> CString { } // Helper type to manage ownership of the strings within a C-style array. +#[cfg_attr(bootstrap, allow(unnameable_types))] +//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(process)` pub struct CStringArray { items: Vec, ptrs: Vec<*const c_char>, diff --git a/library/std/src/sys/windows/c/windows_sys.rs b/library/std/src/sys/windows/c/windows_sys.rs index 02377087173a7..4ba86803fd08b 100644 --- a/library/std/src/sys/windows/c/windows_sys.rs +++ b/library/std/src/sys/windows/c/windows_sys.rs @@ -3647,6 +3647,8 @@ impl ::core::clone::Clone for OBJECT_ATTRIBUTES { pub const OBJ_DONT_REPARSE: i32 = 4096i32; pub const OPEN_ALWAYS: FILE_CREATION_DISPOSITION = 4u32; pub const OPEN_EXISTING: FILE_CREATION_DISPOSITION = 3u32; +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[repr(C)] pub struct OVERLAPPED { pub Internal: usize, @@ -3660,6 +3662,8 @@ impl ::core::clone::Clone for OVERLAPPED { *self } } +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[repr(C)] pub union OVERLAPPED_0 { pub Anonymous: OVERLAPPED_0_0, @@ -3671,6 +3675,8 @@ impl ::core::clone::Clone for OVERLAPPED_0 { *self } } +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[repr(C)] pub struct OVERLAPPED_0_0 { pub Offset: u32, @@ -3784,6 +3790,8 @@ pub const SECURITY_SQOS_PRESENT: FILE_FLAGS_AND_ATTRIBUTES = 1048576u32; pub const SECURITY_VALID_SQOS_FLAGS: FILE_FLAGS_AND_ATTRIBUTES = 2031616u32; pub type SEND_RECV_FLAGS = i32; pub type SET_FILE_POINTER_MOVE_METHOD = u32; +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[repr(C)] pub struct SOCKADDR { pub sa_family: ADDRESS_FAMILY, diff --git a/library/std/src/sys/windows/handle.rs b/library/std/src/sys/windows/handle.rs index 84c1fbde32d2f..7a16a5d3e425c 100644 --- a/library/std/src/sys/windows/handle.rs +++ b/library/std/src/sys/windows/handle.rs @@ -17,6 +17,8 @@ use crate::sys_common::{AsInner, FromInner, IntoInner}; /// An owned container for `HANDLE` object, closing them on Drop. /// /// All methods are inherited through a `Deref` impl to `RawHandle` +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` pub struct Handle(OwnedHandle); impl Handle { diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs index 1ae42cb7eae63..41f4460894b77 100644 --- a/library/std/src/sys/windows/net.rs +++ b/library/std/src/sys/windows/net.rs @@ -27,6 +27,8 @@ pub mod netc { pub use crate::sys::c::*; } +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` pub struct Socket(OwnedSocket); static WSA_CLEANUP: OnceLock i32> = OnceLock::new(); diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index e3493cbb85094..0d19d25dcd26e 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -35,6 +35,8 @@ use libc::{c_void, EXIT_FAILURE, EXIT_SUCCESS}; // Command //////////////////////////////////////////////////////////////////////////////// +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[derive(Clone, Debug, Eq)] #[doc(hidden)] pub struct EnvKey { diff --git a/library/std/src/sys/windows/time.rs b/library/std/src/sys/windows/time.rs index b8209a8544585..bf8604915620a 100644 --- a/library/std/src/sys/windows/time.rs +++ b/library/std/src/sys/windows/time.rs @@ -169,6 +169,8 @@ mod perf_counter { use crate::sys_common::mul_div_u64; use crate::time::Duration; + #[cfg_attr(bootstrap, allow(unnameable_types))] + //~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(time)` pub struct PerformanceCounterInstant { ts: c::LARGE_INTEGER, } diff --git a/library/test/src/event.rs b/library/test/src/event.rs index 80281ebd2d4cd..49b2f9b8973ef 100644 --- a/library/test/src/event.rs +++ b/library/test/src/event.rs @@ -5,6 +5,8 @@ use super::test_result::TestResult; use super::time::TestExecTime; use super::types::{TestDesc, TestId}; +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[derive(Debug, Clone)] pub struct CompletedTest { pub id: TestId, @@ -25,7 +27,8 @@ impl CompletedTest { Self { id, desc, result, exec_time, stdout } } } - +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[derive(Debug, Clone)] pub enum TestEvent { TeFiltered(usize, Option), diff --git a/library/test/src/time.rs b/library/test/src/time.rs index 7fd69d7f7e73c..074fb07ed57b6 100644 --- a/library/test/src/time.rs +++ b/library/test/src/time.rs @@ -82,6 +82,8 @@ impl fmt::Display for TestSuiteExecTime { } /// Structure denoting time limits for test execution. +#[allow(unnameable_types)] +//~^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] pub struct TimeThreshold { pub warn: Duration, diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index e87125a49a6a0..fa6bc67ecf058 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -82,7 +82,13 @@ fn main() { cmd.env("RUST_BACKTRACE", "1"); } - if let Ok(lint_flags) = env::var("RUSTC_LINT_FLAGS") { + if let Ok(mut lint_flags) = env::var("RUSTC_LINT_FLAGS") { + if target.is_none() { + lint_flags = lint_flags + .replace("-Wprivate_interfaces", "") + .replace("-Wprivate_bounds", "") + .replace("-Wunnameable_types", ""); + } cmd.args(lint_flags.split_whitespace()); } diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index c0c749552e654..590522056c060 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1819,6 +1819,13 @@ impl<'a> Builder<'a> { lint_flags.push("-Wunused_lifetimes"); lint_flags.push("-Wsemicolon_in_expressions_from_macros"); + if matches!(mode, Mode::Std) { + rustflags.arg("-Zcrate-attr=feature(type_privacy_lints)"); + lint_flags.push("-Wprivate_interfaces"); + lint_flags.push("-Wprivate_bounds"); + lint_flags.push("-Wunnameable_types"); + } + if self.config.deny_warnings { lint_flags.push("-Dwarnings"); rustdocflags.arg("-Dwarnings"); diff --git a/tests/ui/privacy/unnameable_types.rs b/tests/ui/privacy/unnameable_types.rs index eae20dd9df374..46e249152594b 100644 --- a/tests/ui/privacy/unnameable_types.rs +++ b/tests/ui/privacy/unnameable_types.rs @@ -11,12 +11,12 @@ mod m { pub trait PubTr { //~ ERROR trait `PubTr` is reachable but cannot be named const C : i32 = 0; - type Alias; //~ ERROR associated type `PubTr::Alias` is reachable but cannot be named + type Alias; fn f() {} } impl PubTr for PubStruct { - type Alias = i32; //~ ERROR associated type `::Alias` is reachable but cannot be named + type Alias = i32; fn f() {} } } diff --git a/tests/ui/privacy/unnameable_types.stderr b/tests/ui/privacy/unnameable_types.stderr index 25eb5c9434a8f..904127525758f 100644 --- a/tests/ui/privacy/unnameable_types.stderr +++ b/tests/ui/privacy/unnameable_types.stderr @@ -22,17 +22,5 @@ error: trait `PubTr` is reachable but cannot be named LL | pub trait PubTr { | ^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` -error: associated type `PubTr::Alias` is reachable but cannot be named - --> $DIR/unnameable_types.rs:14:9 - | -LL | type Alias; - | ^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` - -error: associated type `::Alias` is reachable but cannot be named - --> $DIR/unnameable_types.rs:19:9 - | -LL | type Alias = i32; - | ^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` - -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors