Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable type privacy lints in rustc #113284

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<A: Allocator>(s: &[Self], alloc: A) -> Vec<Self, A>
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/vec/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/array/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub(crate) fn drain_array_with<T, R, const N: usize>(
/// 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<T> Drop for Drain<'_, T> {
Expand All @@ -39,6 +41,8 @@ impl<T> Drop for Drain<'_, T> {
}

impl<T> 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;
petrochenkov marked this conversation as resolved.
Show resolved Hide resolved

#[inline]
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/convert/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
10 changes: 10 additions & 0 deletions library/core/src/fmt/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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: (),
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/future/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F: Future> {
Expand All @@ -172,6 +174,8 @@ impl<F: Future> MaybeDone<F> {

#[unstable(feature = "future_join", issue = "91642")]
impl<F: Future> Future for MaybeDone<F> {
#[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<Self::Output> {
Expand Down
6 changes: 6 additions & 0 deletions library/core/src/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R>,
Expand Down Expand Up @@ -172,6 +174,8 @@ impl<I, R> Iterator for GenericShunt<'_, I, R>
where
I: Iterator<Item: Try<Residual = R>>,
{
#[cfg_attr(bootstrap, allow(unnameable_types))]
//~^ reachable at visibility `pub(crate)`, but can only be named at visibility `pub(iter)`
type Item = <I::Item as Try>::Output;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -211,6 +215,8 @@ unsafe impl<I, R> 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]
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/iter/sources/from_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ pub fn from_generator<G: Generator<Return = ()> + 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>(G);

#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> {
#[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<Self::Item> {
Expand Down
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ pub mod primitive;
missing_docs,
missing_debug_implementations,
dead_code,
unnameable_types,
unused_imports,
unsafe_op_in_unsafe_fn
)]
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/num/dec2flt/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/ops/try_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ impl<T> NeverShortCircuit<T> {
}
}

#[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<T> Try for NeverShortCircuit<T> {
Expand All @@ -443,6 +445,8 @@ impl<T> FromResidual for NeverShortCircuit<T> {
}

impl<T> Residual<T> 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<T>;
}

Expand Down
2 changes: 2 additions & 0 deletions library/core/src/slice/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
2 changes: 2 additions & 0 deletions library/core/src/str/lossy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 2 additions & 0 deletions library/portable-simd/crates/core_simd/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions library/portable-simd/crates/core_simd/src/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}

Expand Down
2 changes: 2 additions & 0 deletions library/portable-simd/crates/core_simd/src/lane_count.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions library/portable-simd/crates/core_simd/src/masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
petrochenkov marked this conversation as resolved.
Show resolved Hide resolved
//~^ reachable at visibility `pub`, but can only be named at visibility `pub(vector)`
pub trait Sealed {
fn valid<const LANES: usize>(values: Simd<Self, LANES>) -> bool
where
Expand Down
12 changes: 12 additions & 0 deletions library/portable-simd/crates/core_simd/src/masks/full_masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, const LANES: usize>(Simd<T, LANES>)
where
Expand Down Expand Up @@ -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.)
Expand Down Expand Up @@ -276,6 +280,8 @@ where
T: MaskElement,
LaneCount<LANES>: 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"]
Expand All @@ -290,6 +296,8 @@ where
T: MaskElement,
LaneCount<LANES>: 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"]
Expand All @@ -304,6 +312,8 @@ where
T: MaskElement,
LaneCount<LANES>: 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"]
Expand All @@ -318,6 +328,8 @@ where
T: MaskElement,
LaneCount<LANES>: 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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions library/portable-simd/crates/core_simd/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions library/proc_macro/src/bridge/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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] {
Expand Down
2 changes: 2 additions & 0 deletions library/proc_macro/src/bridge/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions library/proc_macro/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading