Skip to content

Commit

Permalink
privacy: Feature gate new type privacy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jun 15, 2023
1 parent f9097f8 commit d326aed
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 32 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ declare_features! (
/// Allows creation of instances of a struct by moving fields that have
/// not changed from prior instances of the same struct (RFC #2528)
(active, type_changing_struct_update, "1.58.0", Some(86555), None),
/// Allows using type privacy lints (`private_interfaces`, `private_bounds`, `unnameable_types`).
(active, type_privacy_lints, "CURRENT_RUSTC_VERSION", Some(48054), None),
/// Enables rustc to generate code that instructs libstd to NOT ignore SIGPIPE.
(active, unix_sigpipe, "1.65.0", Some(97889), None),
/// Allows unsized fn parameters.
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4263,6 +4263,7 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(type_privacy_lints)]
/// # #![allow(unused)]
/// # #![allow(private_in_public)]
/// #![deny(private_interfaces)]
Expand All @@ -4287,6 +4288,7 @@ declare_lint! {
pub PRIVATE_INTERFACES,
Allow,
"private type in primary interface of an item",
@feature_gate = sym::type_privacy_lints;
}

declare_lint! {
Expand All @@ -4297,6 +4299,7 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(type_privacy_lints)]
/// # #![allow(private_in_public)]
/// # #![allow(unused)]
/// #![deny(private_bounds)]
Expand All @@ -4316,7 +4319,8 @@ declare_lint! {
/// the item actually provides.
pub PRIVATE_BOUNDS,
Allow,
"private type in secondary interface of an item"
"private type in secondary interface of an item",
@feature_gate = sym::type_privacy_lints;
}

declare_lint! {
Expand All @@ -4326,6 +4330,7 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(type_privacy_lints)]
/// # #![allow(unused)]
/// #![deny(unnameable_types)]
/// mod m {
Expand All @@ -4344,5 +4349,6 @@ declare_lint! {
/// you can name the type `T` as well, this lint attempts to enforce this rule.
pub UNNAMEABLE_TYPES,
Allow,
"effective visibility of a type is larger than the area in which it can be named"
"effective visibility of a type is larger than the area in which it can be named",
@feature_gate = sym::type_privacy_lints;
}
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,7 @@ symbols! {
type_length_limit,
type_macros,
type_name,
type_privacy_lints,
u128,
u16,
u32,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-inherent-types/private-in-public.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![feature(inherent_associated_types)]
#![feature(type_privacy_lints)]
#![allow(incomplete_features)]
#![crate_type = "lib"]

#![deny(private_in_public)]
#![warn(private_interfaces)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![crate_type = "lib"]
#![feature(generic_const_exprs)]
#![feature(type_privacy_lints)]
#![allow(incomplete_features)]

#![warn(private_interfaces)]

// In this test both old and new private-in-public diagnostic were emitted.
Expand Down
1 change: 1 addition & 0 deletions tests/ui/error-codes/E0445.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(type_privacy_lints)]
#[warn(private_bounds)]
#[warn(private_interfaces)]

Expand Down
20 changes: 10 additions & 10 deletions tests/ui/error-codes/E0445.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0445]: private trait `Foo` in public interface
--> $DIR/E0445.rs:12:1
--> $DIR/E0445.rs:13:1
|
LL | trait Foo {
| --------- `Foo` declared as private
Expand All @@ -10,23 +10,23 @@ LL | pub trait Bar : Foo {}
warning: trait `Foo` is more private than the item `Bar`
|
note: trait `Bar` is reachable at visibility `pub`
--> $DIR/E0445.rs:12:1
--> $DIR/E0445.rs:13:1
|
LL | pub trait Bar : Foo {}
| ^^^^^^^^^^^^^^^^^^^
note: but trait `Foo` is only usable at visibility `pub(crate)`
--> $DIR/E0445.rs:8:1
--> $DIR/E0445.rs:9:1
|
LL | trait Foo {
| ^^^^^^^^^
note: the lint level is defined here
--> $DIR/E0445.rs:1:8
--> $DIR/E0445.rs:2:8
|
LL | #[warn(private_bounds)]
| ^^^^^^^^^^^^^^

error[E0445]: private trait `Foo` in public interface
--> $DIR/E0445.rs:14:1
--> $DIR/E0445.rs:15:1
|
LL | trait Foo {
| --------- `Foo` declared as private
Expand All @@ -37,18 +37,18 @@ LL | pub struct Bar2<T: Foo>(pub T);
warning: trait `Foo` is more private than the item `Bar2`
|
note: struct `Bar2` is reachable at visibility `pub`
--> $DIR/E0445.rs:14:1
--> $DIR/E0445.rs:15:1
|
LL | pub struct Bar2<T: Foo>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^
note: but trait `Foo` is only usable at visibility `pub(crate)`
--> $DIR/E0445.rs:8:1
--> $DIR/E0445.rs:9:1
|
LL | trait Foo {
| ^^^^^^^^^

error[E0445]: private trait `Foo` in public interface
--> $DIR/E0445.rs:16:1
--> $DIR/E0445.rs:17:1
|
LL | trait Foo {
| --------- `Foo` declared as private
Expand All @@ -59,12 +59,12 @@ LL | pub fn foo<T: Foo> (t: T) {}
warning: trait `Foo` is more private than the item `foo`
|
note: function `foo` is reachable at visibility `pub`
--> $DIR/E0445.rs:16:1
--> $DIR/E0445.rs:17:1
|
LL | pub fn foo<T: Foo> (t: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: but trait `Foo` is only usable at visibility `pub(crate)`
--> $DIR/E0445.rs:8:1
--> $DIR/E0445.rs:9:1
|
LL | trait Foo {
| ^^^^^^^^^
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/feature-gates/feature-gate-type_privacy_lints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// check-pass

#![warn(private_interfaces)] //~ WARN unknown lint
//~| WARN unknown lint
//~| WARN unknown lint
#![warn(private_bounds)] //~ WARN unknown lint
//~| WARN unknown lint
//~| WARN unknown lint
#![warn(unnameable_types)] //~ WARN unknown lint
//~| WARN unknown lint
//~| WARN unknown lint
fn main() {}
93 changes: 93 additions & 0 deletions tests/ui/feature-gates/feature-gate-type_privacy_lints.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
warning: unknown lint: `private_interfaces`
--> $DIR/feature-gate-type_privacy_lints.rs:3:1
|
LL | #![warn(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_interfaces` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
= note: `#[warn(unknown_lints)]` on by default

warning: unknown lint: `private_bounds`
--> $DIR/feature-gate-type_privacy_lints.rs:6:1
|
LL | #![warn(private_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_bounds` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable

warning: unknown lint: `unnameable_types`
--> $DIR/feature-gate-type_privacy_lints.rs:9:1
|
LL | #![warn(unnameable_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `unnameable_types` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable

warning: unknown lint: `private_interfaces`
--> $DIR/feature-gate-type_privacy_lints.rs:3:1
|
LL | #![warn(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_interfaces` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable

warning: unknown lint: `private_bounds`
--> $DIR/feature-gate-type_privacy_lints.rs:6:1
|
LL | #![warn(private_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_bounds` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable

warning: unknown lint: `unnameable_types`
--> $DIR/feature-gate-type_privacy_lints.rs:9:1
|
LL | #![warn(unnameable_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `unnameable_types` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable

warning: unknown lint: `private_interfaces`
--> $DIR/feature-gate-type_privacy_lints.rs:3:1
|
LL | #![warn(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_interfaces` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable

warning: unknown lint: `private_bounds`
--> $DIR/feature-gate-type_privacy_lints.rs:6:1
|
LL | #![warn(private_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_bounds` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable

warning: unknown lint: `unnameable_types`
--> $DIR/feature-gate-type_privacy_lints.rs:9:1
|
LL | #![warn(unnameable_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `unnameable_types` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable

warning: 9 warnings emitted

1 change: 1 addition & 0 deletions tests/ui/issues/issue-18389.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(type_privacy_lints)]
#![warn(private_bounds)]

// In this test both old and new private-in-public diagnostic were emitted.
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/issues/issue-18389.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0445]: private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface
--> $DIR/issue-18389.rs:13:1
--> $DIR/issue-18389.rs:14:1
|
LL | trait Private<P, R> {
| ------------------- `Private<<Self as Public>::P, <Self as Public>::R>` declared as private
Expand All @@ -14,7 +14,7 @@ LL | | > {
warning: trait `Private<<Self as Public>::P, <Self as Public>::R>` is more private than the item `Public`
|
note: trait `Public` is reachable at visibility `pub`
--> $DIR/issue-18389.rs:13:1
--> $DIR/issue-18389.rs:14:1
|
LL | / pub trait Public: Private<
LL | |
Expand All @@ -23,12 +23,12 @@ LL | | <Self as Public>::R
LL | | > {
| |_^
note: but trait `Private<<Self as Public>::P, <Self as Public>::R>` is only usable at visibility `pub(crate)`
--> $DIR/issue-18389.rs:10:1
--> $DIR/issue-18389.rs:11:1
|
LL | trait Private<P, R> {
| ^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/issue-18389.rs:1:9
--> $DIR/issue-18389.rs:2:9
|
LL | #![warn(private_bounds)]
| ^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/privacy/private-in-public-non-principal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(auto_traits)]
#![feature(negative_impls)]

#![feature(type_privacy_lints)]
#![deny(private_interfaces)]

// In this test both old and new private-in-public diagnostic were emitted.
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/privacy/unnameable_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unused)]
#![feature(type_privacy_lints)]
#![allow(private_in_public)]
#![deny(unnameable_types)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/privacy/where-priv-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#![crate_type = "lib"]
#![feature(generic_const_exprs)]
#![feature(type_privacy_lints)]
#![allow(incomplete_features)]

#![warn(private_bounds)]
#![warn(private_interfaces)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/privacy/where-pub-type-impls-priv-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#![crate_type = "lib"]
#![feature(generic_const_exprs)]
#![feature(type_privacy_lints)]
#![allow(incomplete_features)]

#![warn(private_bounds)]

// In this test both old and new private-in-public diagnostic were emitted.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(type_privacy_lints)]
#![allow(non_camel_case_types)] // genus is always capitalized
#![warn(private_interfaces)]
//~^ NOTE the lint level is defined here
Expand Down
Loading

0 comments on commit d326aed

Please sign in to comment.