privacy: Feature gate new type privacy lints

This commit is contained in:
Vadim Petrochenkov 2023-06-15 15:47:38 +03:00
parent f9097f87c9
commit d326aed46f
17 changed files with 149 additions and 32 deletions

View File

@ -539,6 +539,8 @@ pub fn set(&self, features: &mut Features, span: Span) {
/// 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.

View File

@ -4263,6 +4263,7 @@
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(type_privacy_lints)]
/// # #![allow(unused)]
/// # #![allow(private_in_public)]
/// #![deny(private_interfaces)]
@ -4287,6 +4288,7 @@
pub PRIVATE_INTERFACES,
Allow,
"private type in primary interface of an item",
@feature_gate = sym::type_privacy_lints;
}
declare_lint! {
@ -4297,6 +4299,7 @@
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(type_privacy_lints)]
/// # #![allow(private_in_public)]
/// # #![allow(unused)]
/// #![deny(private_bounds)]
@ -4316,7 +4319,8 @@
/// 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! {
@ -4326,6 +4330,7 @@
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(type_privacy_lints)]
/// # #![allow(unused)]
/// #![deny(unnameable_types)]
/// mod m {
@ -4344,5 +4349,6 @@
/// 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;
}

View File

@ -1555,6 +1555,7 @@
type_length_limit,
type_macros,
type_name,
type_privacy_lints,
u128,
u16,
u32,

View File

@ -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)]

View File

@ -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.

View File

@ -1,3 +1,4 @@
#![feature(type_privacy_lints)]
#[warn(private_bounds)]
#[warn(private_interfaces)]

View File

@ -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
@ -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
@ -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
@ -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 {
| ^^^^^^^^^

View File

@ -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() {}

View File

@ -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

View File

@ -1,3 +1,4 @@
#![feature(type_privacy_lints)]
#![warn(private_bounds)]
// In this test both old and new private-in-public diagnostic were emitted.

View File

@ -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
@ -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 | |
@ -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)]
| ^^^^^^^^^^^^^^

View File

@ -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.

View File

@ -1,4 +1,4 @@
#![allow(unused)]
#![feature(type_privacy_lints)]
#![allow(private_in_public)]
#![deny(unnameable_types)]

View File

@ -3,8 +3,8 @@
#![crate_type = "lib"]
#![feature(generic_const_exprs)]
#![feature(type_privacy_lints)]
#![allow(incomplete_features)]
#![warn(private_bounds)]
#![warn(private_interfaces)]

View File

@ -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.

View File

@ -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

View File

@ -1,5 +1,5 @@
error[E0446]: private type `Snail` in public interface
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:27:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:28:1
|
LL | pub(crate) struct Snail;
| ----------------------- `Snail` declared as private
@ -10,23 +10,23 @@ LL | pub type Helix_pomatia = Shell<Snail>;
warning: type `Snail` is more private than the item `Helix_pomatia`
|
note: type alias `Helix_pomatia` is reachable at visibility `pub`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:27:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:28:1
|
LL | pub type Helix_pomatia = Shell<Snail>;
| ^^^^^^^^^^^^^^^^^^^^^^
note: but type `Snail` is only usable at visibility `pub(crate)`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:9:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:10:1
|
LL | pub(crate) struct Snail;
| ^^^^^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:2:9
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:3:9
|
LL | #![warn(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^
error[E0446]: crate-private type `Turtle` in public interface
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:31:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:32:1
|
LL | pub(super) struct Turtle;
| ------------------------ `Turtle` declared as crate-private
@ -37,18 +37,18 @@ LL | pub type Dermochelys_coriacea = Shell<sea::Turtle>;
warning: type `Turtle` is more private than the item `Dermochelys_coriacea`
|
note: type alias `Dermochelys_coriacea` is reachable at visibility `pub`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:31:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:32:1
|
LL | pub type Dermochelys_coriacea = Shell<sea::Turtle>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: but type `Turtle` is only usable at visibility `pub(crate)`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:14:5
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:15:5
|
LL | pub(super) struct Turtle;
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0446]: private type `Tortoise` in public interface
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:35:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:36:1
|
LL | struct Tortoise;
| --------------- `Tortoise` declared as private
@ -59,12 +59,12 @@ LL | pub type Testudo_graeca = Shell<Tortoise>;
warning: type `Tortoise` is more private than the item `Testudo_graeca`
|
note: type alias `Testudo_graeca` is reachable at visibility `pub`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:35:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:36:1
|
LL | pub type Testudo_graeca = Shell<Tortoise>;
| ^^^^^^^^^^^^^^^^^^^^^^^
note: but type `Tortoise` is only usable at visibility `pub(crate)`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:19:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:20:1
|
LL | struct Tortoise;
| ^^^^^^^^^^^^^^^