Skip to content

Commit d326aed

Browse files
committed
privacy: Feature gate new type privacy lints
1 parent f9097f8 commit d326aed

17 files changed

+149
-32
lines changed

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,8 @@ declare_features! (
539539
/// Allows creation of instances of a struct by moving fields that have
540540
/// not changed from prior instances of the same struct (RFC #2528)
541541
(active, type_changing_struct_update, "1.58.0", Some(86555), None),
542+
/// Allows using type privacy lints (`private_interfaces`, `private_bounds`, `unnameable_types`).
543+
(active, type_privacy_lints, "CURRENT_RUSTC_VERSION", Some(48054), None),
542544
/// Enables rustc to generate code that instructs libstd to NOT ignore SIGPIPE.
543545
(active, unix_sigpipe, "1.65.0", Some(97889), None),
544546
/// Allows unsized fn parameters.

compiler/rustc_lint_defs/src/builtin.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -4263,6 +4263,7 @@ declare_lint! {
42634263
/// ### Example
42644264
///
42654265
/// ```rust,compile_fail
4266+
/// # #![feature(type_privacy_lints)]
42664267
/// # #![allow(unused)]
42674268
/// # #![allow(private_in_public)]
42684269
/// #![deny(private_interfaces)]
@@ -4287,6 +4288,7 @@ declare_lint! {
42874288
pub PRIVATE_INTERFACES,
42884289
Allow,
42894290
"private type in primary interface of an item",
4291+
@feature_gate = sym::type_privacy_lints;
42904292
}
42914293

42924294
declare_lint! {
@@ -4297,6 +4299,7 @@ declare_lint! {
42974299
/// ### Example
42984300
///
42994301
/// ```rust,compile_fail
4302+
/// # #![feature(type_privacy_lints)]
43004303
/// # #![allow(private_in_public)]
43014304
/// # #![allow(unused)]
43024305
/// #![deny(private_bounds)]
@@ -4316,7 +4319,8 @@ declare_lint! {
43164319
/// the item actually provides.
43174320
pub PRIVATE_BOUNDS,
43184321
Allow,
4319-
"private type in secondary interface of an item"
4322+
"private type in secondary interface of an item",
4323+
@feature_gate = sym::type_privacy_lints;
43204324
}
43214325

43224326
declare_lint! {
@@ -4326,6 +4330,7 @@ declare_lint! {
43264330
/// ### Example
43274331
///
43284332
/// ```rust,compile_fail
4333+
/// # #![feature(type_privacy_lints)]
43294334
/// # #![allow(unused)]
43304335
/// #![deny(unnameable_types)]
43314336
/// mod m {
@@ -4344,5 +4349,6 @@ declare_lint! {
43444349
/// you can name the type `T` as well, this lint attempts to enforce this rule.
43454350
pub UNNAMEABLE_TYPES,
43464351
Allow,
4347-
"effective visibility of a type is larger than the area in which it can be named"
4352+
"effective visibility of a type is larger than the area in which it can be named",
4353+
@feature_gate = sym::type_privacy_lints;
43484354
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,7 @@ symbols! {
15551555
type_length_limit,
15561556
type_macros,
15571557
type_name,
1558+
type_privacy_lints,
15581559
u128,
15591560
u16,
15601561
u32,

tests/ui/associated-inherent-types/private-in-public.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(inherent_associated_types)]
2+
#![feature(type_privacy_lints)]
23
#![allow(incomplete_features)]
34
#![crate_type = "lib"]
4-
55
#![deny(private_in_public)]
66
#![warn(private_interfaces)]
77

tests/ui/const-generics/generic_const_exprs/eval-privacy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![crate_type = "lib"]
22
#![feature(generic_const_exprs)]
3+
#![feature(type_privacy_lints)]
34
#![allow(incomplete_features)]
4-
55
#![warn(private_interfaces)]
66

77
// In this test both old and new private-in-public diagnostic were emitted.

tests/ui/error-codes/E0445.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(type_privacy_lints)]
12
#[warn(private_bounds)]
23
#[warn(private_interfaces)]
34

tests/ui/error-codes/E0445.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0445]: private trait `Foo` in public interface
2-
--> $DIR/E0445.rs:12:1
2+
--> $DIR/E0445.rs:13:1
33
|
44
LL | trait Foo {
55
| --------- `Foo` declared as private
@@ -10,23 +10,23 @@ LL | pub trait Bar : Foo {}
1010
warning: trait `Foo` is more private than the item `Bar`
1111
|
1212
note: trait `Bar` is reachable at visibility `pub`
13-
--> $DIR/E0445.rs:12:1
13+
--> $DIR/E0445.rs:13:1
1414
|
1515
LL | pub trait Bar : Foo {}
1616
| ^^^^^^^^^^^^^^^^^^^
1717
note: but trait `Foo` is only usable at visibility `pub(crate)`
18-
--> $DIR/E0445.rs:8:1
18+
--> $DIR/E0445.rs:9:1
1919
|
2020
LL | trait Foo {
2121
| ^^^^^^^^^
2222
note: the lint level is defined here
23-
--> $DIR/E0445.rs:1:8
23+
--> $DIR/E0445.rs:2:8
2424
|
2525
LL | #[warn(private_bounds)]
2626
| ^^^^^^^^^^^^^^
2727

2828
error[E0445]: private trait `Foo` in public interface
29-
--> $DIR/E0445.rs:14:1
29+
--> $DIR/E0445.rs:15:1
3030
|
3131
LL | trait Foo {
3232
| --------- `Foo` declared as private
@@ -37,18 +37,18 @@ LL | pub struct Bar2<T: Foo>(pub T);
3737
warning: trait `Foo` is more private than the item `Bar2`
3838
|
3939
note: struct `Bar2` is reachable at visibility `pub`
40-
--> $DIR/E0445.rs:14:1
40+
--> $DIR/E0445.rs:15:1
4141
|
4242
LL | pub struct Bar2<T: Foo>(pub T);
4343
| ^^^^^^^^^^^^^^^^^^^^^^^
4444
note: but trait `Foo` is only usable at visibility `pub(crate)`
45-
--> $DIR/E0445.rs:8:1
45+
--> $DIR/E0445.rs:9:1
4646
|
4747
LL | trait Foo {
4848
| ^^^^^^^^^
4949

5050
error[E0445]: private trait `Foo` in public interface
51-
--> $DIR/E0445.rs:16:1
51+
--> $DIR/E0445.rs:17:1
5252
|
5353
LL | trait Foo {
5454
| --------- `Foo` declared as private
@@ -59,12 +59,12 @@ LL | pub fn foo<T: Foo> (t: T) {}
5959
warning: trait `Foo` is more private than the item `foo`
6060
|
6161
note: function `foo` is reachable at visibility `pub`
62-
--> $DIR/E0445.rs:16:1
62+
--> $DIR/E0445.rs:17:1
6363
|
6464
LL | pub fn foo<T: Foo> (t: T) {}
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6666
note: but trait `Foo` is only usable at visibility `pub(crate)`
67-
--> $DIR/E0445.rs:8:1
67+
--> $DIR/E0445.rs:9:1
6868
|
6969
LL | trait Foo {
7070
| ^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
3+
#![warn(private_interfaces)] //~ WARN unknown lint
4+
//~| WARN unknown lint
5+
//~| WARN unknown lint
6+
#![warn(private_bounds)] //~ WARN unknown lint
7+
//~| WARN unknown lint
8+
//~| WARN unknown lint
9+
#![warn(unnameable_types)] //~ WARN unknown lint
10+
//~| WARN unknown lint
11+
//~| WARN unknown lint
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
warning: unknown lint: `private_interfaces`
2+
--> $DIR/feature-gate-type_privacy_lints.rs:3:1
3+
|
4+
LL | #![warn(private_interfaces)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: the `private_interfaces` lint is unstable
8+
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
9+
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
10+
= note: `#[warn(unknown_lints)]` on by default
11+
12+
warning: unknown lint: `private_bounds`
13+
--> $DIR/feature-gate-type_privacy_lints.rs:6:1
14+
|
15+
LL | #![warn(private_bounds)]
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^
17+
|
18+
= note: the `private_bounds` lint is unstable
19+
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
20+
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
21+
22+
warning: unknown lint: `unnameable_types`
23+
--> $DIR/feature-gate-type_privacy_lints.rs:9:1
24+
|
25+
LL | #![warn(unnameable_types)]
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
27+
|
28+
= note: the `unnameable_types` lint is unstable
29+
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
30+
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
31+
32+
warning: unknown lint: `private_interfaces`
33+
--> $DIR/feature-gate-type_privacy_lints.rs:3:1
34+
|
35+
LL | #![warn(private_interfaces)]
36+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
|
38+
= note: the `private_interfaces` lint is unstable
39+
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
40+
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
41+
42+
warning: unknown lint: `private_bounds`
43+
--> $DIR/feature-gate-type_privacy_lints.rs:6:1
44+
|
45+
LL | #![warn(private_bounds)]
46+
| ^^^^^^^^^^^^^^^^^^^^^^^^
47+
|
48+
= note: the `private_bounds` lint is unstable
49+
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
50+
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
51+
52+
warning: unknown lint: `unnameable_types`
53+
--> $DIR/feature-gate-type_privacy_lints.rs:9:1
54+
|
55+
LL | #![warn(unnameable_types)]
56+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
57+
|
58+
= note: the `unnameable_types` lint is unstable
59+
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
60+
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
61+
62+
warning: unknown lint: `private_interfaces`
63+
--> $DIR/feature-gate-type_privacy_lints.rs:3:1
64+
|
65+
LL | #![warn(private_interfaces)]
66+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67+
|
68+
= note: the `private_interfaces` lint is unstable
69+
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
70+
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
71+
72+
warning: unknown lint: `private_bounds`
73+
--> $DIR/feature-gate-type_privacy_lints.rs:6:1
74+
|
75+
LL | #![warn(private_bounds)]
76+
| ^^^^^^^^^^^^^^^^^^^^^^^^
77+
|
78+
= note: the `private_bounds` lint is unstable
79+
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
80+
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
81+
82+
warning: unknown lint: `unnameable_types`
83+
--> $DIR/feature-gate-type_privacy_lints.rs:9:1
84+
|
85+
LL | #![warn(unnameable_types)]
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
|
88+
= note: the `unnameable_types` lint is unstable
89+
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
90+
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
91+
92+
warning: 9 warnings emitted
93+

tests/ui/issues/issue-18389.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(type_privacy_lints)]
12
#![warn(private_bounds)]
23

34
// In this test both old and new private-in-public diagnostic were emitted.

tests/ui/issues/issue-18389.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0445]: private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface
2-
--> $DIR/issue-18389.rs:13:1
2+
--> $DIR/issue-18389.rs:14:1
33
|
44
LL | trait Private<P, R> {
55
| ------------------- `Private<<Self as Public>::P, <Self as Public>::R>` declared as private
@@ -14,7 +14,7 @@ LL | | > {
1414
warning: trait `Private<<Self as Public>::P, <Self as Public>::R>` is more private than the item `Public`
1515
|
1616
note: trait `Public` is reachable at visibility `pub`
17-
--> $DIR/issue-18389.rs:13:1
17+
--> $DIR/issue-18389.rs:14:1
1818
|
1919
LL | / pub trait Public: Private<
2020
LL | |
@@ -23,12 +23,12 @@ LL | | <Self as Public>::R
2323
LL | | > {
2424
| |_^
2525
note: but trait `Private<<Self as Public>::P, <Self as Public>::R>` is only usable at visibility `pub(crate)`
26-
--> $DIR/issue-18389.rs:10:1
26+
--> $DIR/issue-18389.rs:11:1
2727
|
2828
LL | trait Private<P, R> {
2929
| ^^^^^^^^^^^^^^^^^^^
3030
note: the lint level is defined here
31-
--> $DIR/issue-18389.rs:1:9
31+
--> $DIR/issue-18389.rs:2:9
3232
|
3333
LL | #![warn(private_bounds)]
3434
| ^^^^^^^^^^^^^^

tests/ui/privacy/private-in-public-non-principal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(auto_traits)]
22
#![feature(negative_impls)]
3-
3+
#![feature(type_privacy_lints)]
44
#![deny(private_interfaces)]
55

66
// In this test both old and new private-in-public diagnostic were emitted.

tests/ui/privacy/unnameable_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(unused)]
1+
#![feature(type_privacy_lints)]
22
#![allow(private_in_public)]
33
#![deny(unnameable_types)]
44

tests/ui/privacy/where-priv-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#![crate_type = "lib"]
55
#![feature(generic_const_exprs)]
6+
#![feature(type_privacy_lints)]
67
#![allow(incomplete_features)]
7-
88
#![warn(private_bounds)]
99
#![warn(private_interfaces)]
1010

tests/ui/privacy/where-pub-type-impls-priv-trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#![crate_type = "lib"]
44
#![feature(generic_const_exprs)]
5+
#![feature(type_privacy_lints)]
56
#![allow(incomplete_features)]
6-
77
#![warn(private_bounds)]
88

99
// In this test both old and new private-in-public diagnostic were emitted.

tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(type_privacy_lints)]
12
#![allow(non_camel_case_types)] // genus is always capitalized
23
#![warn(private_interfaces)]
34
//~^ NOTE the lint level is defined here

0 commit comments

Comments
 (0)