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

Replace old private-in-public diagnostic with type privacy lints #113126

Merged
merged 1 commit into from
Sep 1, 2023
Merged
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
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ E0794: include_str!("./error_codes/E0794.md"),
// E0420, // merged into 532
// E0421, // merged into 531
// E0427, // merged into 530
// E0445, // merged into 446 and type privacy lints
// E0456, // plugin `..` is not available for triple `..`
// E0465, // removed: merged with E0464
// E0467, // removed
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_error_codes/src/error_codes/E0445.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
A private trait was used on a public type parameter bound.
#### Note: this error code is no longer emitted by the compiler.

Erroneous code examples:
A private trait was used on a public type parameter bound.

```compile_fail,E0445
#![deny(private_in_public)]
Previously erroneous code examples:

```
trait Foo {
petrochenkov marked this conversation as resolved.
Show resolved Hide resolved
fn dummy(&self) { }
}
Expand Down
46 changes: 25 additions & 21 deletions compiler/rustc_error_codes/src/error_codes/E0446.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
A private type was used in a public type signature.
A private type or trait was used in a public associated type signature.

Erroneous code example:

```compile_fail,E0446
#![deny(private_in_public)]
struct Bar(u32);

mod foo {
use crate::Bar;
pub fn bar() -> Bar { // error: private type in public interface
Bar(0)
}
struct Bar;

petrochenkov marked this conversation as resolved.
Show resolved Hide resolved
pub trait PubTr {
type Alias;
}

impl PubTr for u8 {
type Alias = Bar; // error private type in public interface
}

fn main() {}
Expand All @@ -22,13 +22,14 @@ This is done by using pub(crate) or pub(in crate::my_mod::etc)
Example:

```
struct Bar(u32);
struct Bar;

pub(crate) trait PubTr { // only public to crate root
type Alias;
}

mod foo {
use crate::Bar;
pub(crate) fn bar() -> Bar { // only public to crate root
Bar(0)
}
impl PubTr for u8 {
type Alias = Bar;
}

fn main() {}
Expand All @@ -38,12 +39,15 @@ The other way to solve this error is to make the private type public.
Example:

```
pub struct Bar(u32); // we set the Bar type public
mod foo {
use crate::Bar;
pub fn bar() -> Bar { // ok!
Bar(0)
}

pub struct Bar; // we set the Bar trait public

pub trait PubTr {
type Alias;
}

impl PubTr for u8 {
type Alias = Bar;
}

fn main() {}
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ fn register_builtins(store: &mut LintStore) {
"converted into hard error, see issue #82523 \
<https://github.com/rust-lang/rust/issues/82523> for more information",
);
store.register_removed(
"private_in_public",
"replaced with another group of lints, see RFC \
<https://rust-lang.github.io/rfcs/2145-type-privacy.html> for more information",
);
}

fn register_internals(store: &mut LintStore) {
Expand Down
49 changes: 2 additions & 47 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,44 +982,6 @@ declare_lint! {
"detects trivial casts of numeric types which could be removed"
}

declare_lint! {
/// The `private_in_public` lint detects private items in public
/// interfaces not caught by the old implementation.
///
/// ### Example
///
/// ```rust
/// # #![allow(unused)]
/// struct SemiPriv;
///
/// mod m1 {
/// struct Priv;
/// impl super::SemiPriv {
/// pub fn f(_: Priv) {}
/// }
/// }
/// # fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The visibility rules are intended to prevent exposing private items in
/// public interfaces. This is a [future-incompatible] lint to transition
/// this to a hard error in the future. See [issue #34537] for more
/// details.
///
/// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub PRIVATE_IN_PUBLIC,
Warn,
"detect private items in public interfaces not caught by the old implementation",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
};
}

declare_lint! {
/// The `invalid_alignment` lint detects dereferences of misaligned pointers during
/// constant evaluation.
Expand Down Expand Up @@ -3374,7 +3336,6 @@ declare_lint_pass! {
PATTERNS_IN_FNS_WITHOUT_BODY,
POINTER_STRUCTURAL_MATCH,
PRIVATE_BOUNDS,
PRIVATE_IN_PUBLIC,
PRIVATE_INTERFACES,
PROC_MACRO_BACK_COMPAT,
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
Expand Down Expand Up @@ -4293,9 +4254,7 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(type_privacy_lints)]
/// # #![allow(unused)]
/// # #![allow(private_in_public)]
/// #![deny(private_interfaces)]
/// struct SemiPriv;
///
Expand All @@ -4316,9 +4275,8 @@ declare_lint! {
/// Having something private in primary interface guarantees that
/// the item will be unusable from outer modules due to type privacy.
pub PRIVATE_INTERFACES,
Allow,
Warn,
"private type in primary interface of an item",
@feature_gate = sym::type_privacy_lints;
}

declare_lint! {
Expand All @@ -4329,8 +4287,6 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(type_privacy_lints)]
/// # #![allow(private_in_public)]
/// # #![allow(unused)]
/// #![deny(private_bounds)]
///
Expand All @@ -4348,9 +4304,8 @@ declare_lint! {
/// Having private types or traits in item bounds makes it less clear what interface
/// the item actually provides.
pub PRIVATE_BOUNDS,
Allow,
Warn,
"private type in secondary interface of an item",
@feature_gate = sym::type_privacy_lints;
}

declare_lint! {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,6 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
tcx.sess.local_stable_crate_id().hash_stable(&mut hcx, &mut stable_hasher);
// Hash visibility information since it does not appear in HIR.
resolutions.visibilities.hash_stable(&mut hcx, &mut stable_hasher);
resolutions.has_pub_restricted.hash_stable(&mut hcx, &mut stable_hasher);
stable_hasher.finish()
});

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ pub struct ResolverOutputs {
#[derive(Debug)]
pub struct ResolverGlobalCtxt {
pub visibilities: FxHashMap<LocalDefId, Visibility>,
/// This field is used to decide whether we should make `PRIVATE_IN_PUBLIC` a hard error.
pub has_pub_restricted: bool,
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
pub expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
pub effective_visibilities: EffectiveVisibilities,
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_privacy/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ privacy_in_public_interface = {$vis_descr} {$kind} `{$descr}` in public interfac

privacy_item_is_private = {$kind} `{$descr}` is private
.label = private {$kind}
privacy_private_in_public_lint =
{$vis_descr} {$kind} `{$descr}` in public interface (error {$kind ->
[trait] E0445
*[other] E0446
})

privacy_private_interface_or_bounds_lint = {$ty_kind} `{$ty_descr}` is more private than the item `{$item_descr}`
.item_label = {$item_kind} `{$item_descr}` is reachable at visibility `{$item_vis_descr}`
petrochenkov marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
23 changes: 0 additions & 23 deletions compiler/rustc_privacy/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,6 @@ pub struct UnnamedItemIsPrivate {
pub kind: &'static str,
}

// Duplicate of `InPublicInterface` but with a different error code, shares the same slug.
#[derive(Diagnostic)]
#[diag(privacy_in_public_interface, code = "E0445")]
pub struct InPublicInterfaceTraits<'a> {
#[primary_span]
#[label]
pub span: Span,
pub vis_descr: &'static str,
pub kind: &'a str,
pub descr: DiagnosticArgFromDisplay<'a>,
#[label(privacy_visibility_label)]
pub vis_span: Span,
}

// Duplicate of `InPublicInterfaceTraits` but with a different error code, shares the same slug.
#[derive(Diagnostic)]
#[diag(privacy_in_public_interface, code = "E0446")]
pub struct InPublicInterface<'a> {
Expand Down Expand Up @@ -91,14 +76,6 @@ pub struct FromPrivateDependencyInPublicInterface<'a> {
pub krate: Symbol,
}

#[derive(LintDiagnostic)]
#[diag(privacy_private_in_public_lint)]
pub struct PrivateInPublicLint<'a> {
pub vis_descr: &'static str,
pub kind: &'a str,
pub descr: DiagnosticArgFromDisplay<'a>,
}

#[derive(LintDiagnostic)]
#[diag(privacy_unnameable_types_lint)]
pub struct UnnameableTypesLint<'a> {
Expand Down
Loading
Loading