diff options
author | Bryanskiy <ivakin.kir@gmail.com> | 2023-05-18 14:57:45 +0300 |
---|---|---|
committer | Bryanskiy <ivakin.kir@gmail.com> | 2023-06-12 01:02:19 +0300 |
commit | 6d46382f6f0688df0fc5c67386f86ccd6fdb975f (patch) | |
tree | da222fe6ab404e953e1683070bdd60a700b5991c /tests/ui/privacy | |
parent | d0ee1908ed791d3e91d2ad74ba502eaa203cff6d (diff) |
Private-in-public lints implementation
Diffstat (limited to 'tests/ui/privacy')
-rw-r--r-- | tests/ui/privacy/private-in-public-non-principal.rs | 6 | ||||
-rw-r--r-- | tests/ui/privacy/private-in-public-non-principal.stderr | 26 | ||||
-rw-r--r-- | tests/ui/privacy/private-inferred-type-1.rs | 10 | ||||
-rw-r--r-- | tests/ui/privacy/private-inferred-type-1.stderr | 18 | ||||
-rw-r--r-- | tests/ui/privacy/unnameable_types.rs | 30 | ||||
-rw-r--r-- | tests/ui/privacy/unnameable_types.stderr | 38 | ||||
-rw-r--r-- | tests/ui/privacy/where-priv-type.rs | 6 | ||||
-rw-r--r-- | tests/ui/privacy/where-priv-type.stderr | 110 | ||||
-rw-r--r-- | tests/ui/privacy/where-pub-type-impls-priv-trait.rs | 5 | ||||
-rw-r--r-- | tests/ui/privacy/where-pub-type-impls-priv-trait.stderr | 88 |
10 files changed, 317 insertions, 20 deletions
diff --git a/tests/ui/privacy/private-in-public-non-principal.rs b/tests/ui/privacy/private-in-public-non-principal.rs index ac1d5a9e6a2..a80c1541463 100644 --- a/tests/ui/privacy/private-in-public-non-principal.rs +++ b/tests/ui/privacy/private-in-public-non-principal.rs @@ -1,6 +1,12 @@ #![feature(auto_traits)] #![feature(negative_impls)] +#![deny(private_interfaces)] + +// In this test both old and new private-in-public diagnostic were emitted. +// Old diagnostic will be deleted soon. +// See https://rust-lang.github.io/rfcs/2145-type-privacy.html. + pub trait PubPrincipal {} auto trait PrivNonPrincipal {} diff --git a/tests/ui/privacy/private-in-public-non-principal.stderr b/tests/ui/privacy/private-in-public-non-principal.stderr index de20cada42e..9fc12affe4b 100644 --- a/tests/ui/privacy/private-in-public-non-principal.stderr +++ b/tests/ui/privacy/private-in-public-non-principal.stderr @@ -1,5 +1,5 @@ warning: private trait `PrivNonPrincipal` in public interface (error E0445) - --> $DIR/private-in-public-non-principal.rs:7:1 + --> $DIR/private-in-public-non-principal.rs:13:1 | LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,17 +8,35 @@ LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> = note: `#[warn(private_in_public)]` on by default +error: trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal` + | +note: function `leak_dyn_nonprincipal` is reachable at visibility `pub` + --> $DIR/private-in-public-non-principal.rs:13:1 + | +LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: but trait `PrivNonPrincipal` is only usable at visibility `pub(crate)` + --> $DIR/private-in-public-non-principal.rs:11:1 + | +LL | auto trait PrivNonPrincipal {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/private-in-public-non-principal.rs:4:9 + | +LL | #![deny(private_interfaces)] + | ^^^^^^^^^^^^^^^^^^ + error: missing documentation for an associated function - --> $DIR/private-in-public-non-principal.rs:14:9 + --> $DIR/private-in-public-non-principal.rs:20:9 | LL | pub fn check_doc_lint() {} | ^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/private-in-public-non-principal.rs:11:8 + --> $DIR/private-in-public-non-principal.rs:17:8 | LL | #[deny(missing_docs)] | ^^^^^^^^^^^^ -error: aborting due to previous error; 1 warning emitted +error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui/privacy/private-inferred-type-1.rs b/tests/ui/privacy/private-inferred-type-1.rs index d633189e3fb..b3eba53dd13 100644 --- a/tests/ui/privacy/private-inferred-type-1.rs +++ b/tests/ui/privacy/private-inferred-type-1.rs @@ -5,14 +5,24 @@ trait TyParam { fn ty_param_secret(&self); } +trait Ref { + fn ref_secret(self); +} + mod m { struct Priv; impl ::Arr0 for [Priv; 0] { fn arr0_secret(&self) {} } impl ::TyParam for Option<Priv> { fn ty_param_secret(&self) {} } + impl<'a> ::Ref for &'a Priv { fn ref_secret(self) {} } } +fn anyref<'a, T>() -> &'a T { panic!() } + fn main() { [].arr0_secret(); //~ ERROR type `Priv` is private None.ty_param_secret(); //~ ERROR type `Priv` is private + Ref::ref_secret(anyref()); + //~^ ERROR type `Priv` is private + //~| ERROR type `Priv` is private } diff --git a/tests/ui/privacy/private-inferred-type-1.stderr b/tests/ui/privacy/private-inferred-type-1.stderr index 245789f4353..47c11d6ec76 100644 --- a/tests/ui/privacy/private-inferred-type-1.stderr +++ b/tests/ui/privacy/private-inferred-type-1.stderr @@ -1,14 +1,26 @@ error: type `Priv` is private - --> $DIR/private-inferred-type-1.rs:16:5 + --> $DIR/private-inferred-type-1.rs:23:5 | LL | [].arr0_secret(); | ^^^^^^^^^^^^^^^^ private type error: type `Priv` is private - --> $DIR/private-inferred-type-1.rs:17:5 + --> $DIR/private-inferred-type-1.rs:24:5 | LL | None.ty_param_secret(); | ^^^^^^^^^^^^^^^^^^^^^^ private type -error: aborting due to 2 previous errors +error: type `Priv` is private + --> $DIR/private-inferred-type-1.rs:25:5 + | +LL | Ref::ref_secret(anyref()); + | ^^^^^^^^^^^^^^^ private type + +error: type `Priv` is private + --> $DIR/private-inferred-type-1.rs:25:21 + | +LL | Ref::ref_secret(anyref()); + | ^^^^^^^^ private type + +error: aborting due to 4 previous errors diff --git a/tests/ui/privacy/unnameable_types.rs b/tests/ui/privacy/unnameable_types.rs new file mode 100644 index 00000000000..8b53f372fc9 --- /dev/null +++ b/tests/ui/privacy/unnameable_types.rs @@ -0,0 +1,30 @@ +#![allow(unused)] +#![allow(private_in_public)] +#![deny(unnameable_types)] + +mod m { + pub struct PubStruct(pub i32); //~ ERROR struct `PubStruct` is reachable but cannot be named + + pub enum PubE { //~ ERROR enum `PubE` is reachable but cannot be named + V(i32), + } + + pub trait PubTr { //~ ERROR trait `PubTr` is reachable but cannot be named + const C : i32 = 0; + type Alias; //~ ERROR associated type `PubTr::Alias` is reachable but cannot be named + fn f() {} + } + + impl PubTr for PubStruct { + type Alias = i32; //~ ERROR associated type `<PubStruct as PubTr>::Alias` is reachable but cannot be named + fn f() {} + } +} + +pub trait Voldemort<T> {} + +impl Voldemort<m::PubStruct> for i32 {} +impl Voldemort<m::PubE> for i32 {} +impl<T> Voldemort<T> for u32 where T: m::PubTr {} + +fn main() {} diff --git a/tests/ui/privacy/unnameable_types.stderr b/tests/ui/privacy/unnameable_types.stderr new file mode 100644 index 00000000000..25eb5c9434a --- /dev/null +++ b/tests/ui/privacy/unnameable_types.stderr @@ -0,0 +1,38 @@ +error: struct `PubStruct` is reachable but cannot be named + --> $DIR/unnameable_types.rs:6:5 + | +LL | pub struct PubStruct(pub i32); + | ^^^^^^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` + | +note: the lint level is defined here + --> $DIR/unnameable_types.rs:3:9 + | +LL | #![deny(unnameable_types)] + | ^^^^^^^^^^^^^^^^ + +error: enum `PubE` is reachable but cannot be named + --> $DIR/unnameable_types.rs:8:5 + | +LL | pub enum PubE { + | ^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` + +error: trait `PubTr` is reachable but cannot be named + --> $DIR/unnameable_types.rs:12:5 + | +LL | pub trait PubTr { + | ^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` + +error: associated type `PubTr::Alias` is reachable but cannot be named + --> $DIR/unnameable_types.rs:14:9 + | +LL | type Alias; + | ^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` + +error: associated type `<PubStruct as PubTr>::Alias` is reachable but cannot be named + --> $DIR/unnameable_types.rs:19:9 + | +LL | type Alias = i32; + | ^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)` + +error: aborting due to 5 previous errors + diff --git a/tests/ui/privacy/where-priv-type.rs b/tests/ui/privacy/where-priv-type.rs index 66ee9c4bbd8..9899902dd88 100644 --- a/tests/ui/privacy/where-priv-type.rs +++ b/tests/ui/privacy/where-priv-type.rs @@ -5,6 +5,12 @@ #![feature(generic_const_exprs)] #![allow(incomplete_features)] +#![warn(private_bounds)] +#![warn(private_interfaces)] + +// In this test both old and new private-in-public diagnostic were emitted. +// Old diagnostic will be deleted soon. +// See https://rust-lang.github.io/rfcs/2145-type-privacy.html. struct PrivTy; trait PrivTr {} diff --git a/tests/ui/privacy/where-priv-type.stderr b/tests/ui/privacy/where-priv-type.stderr index c5fb2cdb0cf..2830fa6cd44 100644 --- a/tests/ui/privacy/where-priv-type.stderr +++ b/tests/ui/privacy/where-priv-type.stderr @@ -1,5 +1,5 @@ warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:19:1 + --> $DIR/where-priv-type.rs:25:1 | LL | pub struct S | ^^^^^^^^^^^^ @@ -8,8 +8,26 @@ LL | pub struct S = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> = note: `#[warn(private_in_public)]` on by default +warning: type `PrivTy` is more private than the item `S` + | +note: struct `S` is reachable at visibility `pub` + --> $DIR/where-priv-type.rs:25:1 + | +LL | pub struct S + | ^^^^^^^^^^^^ +note: but type `PrivTy` is only usable at visibility `pub(crate)` + --> $DIR/where-priv-type.rs:15:1 + | +LL | struct PrivTy; + | ^^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/where-priv-type.rs:8:9 + | +LL | #![warn(private_bounds)] + | ^^^^^^^^^^^^^^ + warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:27:1 + --> $DIR/where-priv-type.rs:33:1 | LL | pub enum E | ^^^^^^^^^^ @@ -17,8 +35,21 @@ LL | pub enum E = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +warning: type `PrivTy` is more private than the item `E` + | +note: enum `E` is reachable at visibility `pub` + --> $DIR/where-priv-type.rs:33:1 + | +LL | pub enum E + | ^^^^^^^^^^ +note: but type `PrivTy` is only usable at visibility `pub(crate)` + --> $DIR/where-priv-type.rs:15:1 + | +LL | struct PrivTy; + | ^^^^^^^^^^^^^ + warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:35:1 + --> $DIR/where-priv-type.rs:41:1 | LL | / pub fn f() LL | | @@ -30,8 +61,25 @@ LL | | PrivTy: = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +warning: type `PrivTy` is more private than the item `f` + | +note: function `f` is reachable at visibility `pub` + --> $DIR/where-priv-type.rs:41:1 + | +LL | / pub fn f() +LL | | +LL | | +LL | | where +LL | | PrivTy: + | |___________^ +note: but type `PrivTy` is only usable at visibility `pub(crate)` + --> $DIR/where-priv-type.rs:15:1 + | +LL | struct PrivTy; + | ^^^^^^^^^^^^^ + error[E0446]: private type `PrivTy` in public interface - --> $DIR/where-priv-type.rs:43:1 + --> $DIR/where-priv-type.rs:49:1 | LL | struct PrivTy; | ------------- `PrivTy` declared as private @@ -39,8 +87,21 @@ LL | struct PrivTy; LL | impl S | ^^^^^^ can't leak private type +warning: type `PrivTy` is more private than the item `S` + | +note: implementation `S` is reachable at visibility `pub` + --> $DIR/where-priv-type.rs:49:1 + | +LL | impl S + | ^^^^^^ +note: but type `PrivTy` is only usable at visibility `pub(crate)` + --> $DIR/where-priv-type.rs:15:1 + | +LL | struct PrivTy; + | ^^^^^^^^^^^^^ + warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:48:5 + --> $DIR/where-priv-type.rs:54:5 | LL | / pub fn f() LL | | @@ -52,8 +113,25 @@ LL | | PrivTy: = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> +warning: type `PrivTy` is more private than the item `S::f` + | +note: associated function `S::f` is reachable at visibility `pub` + --> $DIR/where-priv-type.rs:54:5 + | +LL | / pub fn f() +LL | | +LL | | +LL | | where +LL | | PrivTy: + | |_______________^ +note: but type `PrivTy` is only usable at visibility `pub(crate)` + --> $DIR/where-priv-type.rs:15:1 + | +LL | struct PrivTy; + | ^^^^^^^^^^^^^ + error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface - --> $DIR/where-priv-type.rs:80:5 + --> $DIR/where-priv-type.rs:86:5 | LL | type AssocTy = Const<{ my_const_fn(U) }>; | ^^^^^^^^^^^^ can't leak private type @@ -61,6 +139,24 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>; LL | const fn my_const_fn(val: u8) -> u8 { | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private -error: aborting due to 2 previous errors; 4 warnings emitted +warning: type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy` + | +note: associated type `<Const<U> as Trait>::AssocTy` is reachable at visibility `pub` + --> $DIR/where-priv-type.rs:86:5 + | +LL | type AssocTy = Const<{ my_const_fn(U) }>; + | ^^^^^^^^^^^^ +note: but type `fn(u8) -> u8 {my_const_fn}` is only usable at visibility `pub(crate)` + --> $DIR/where-priv-type.rs:93:1 + | +LL | const fn my_const_fn(val: u8) -> u8 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/where-priv-type.rs:9:9 + | +LL | #![warn(private_interfaces)] + | ^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors; 10 warnings emitted For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/privacy/where-pub-type-impls-priv-trait.rs b/tests/ui/privacy/where-pub-type-impls-priv-trait.rs index 87c211df169..3aad893eae2 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.rs +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.rs @@ -4,6 +4,11 @@ #![feature(generic_const_exprs)] #![allow(incomplete_features)] +#![warn(private_bounds)] + +// In this test both old and new private-in-public diagnostic were emitted. +// Old diagnostic will be deleted soon. +// See https://rust-lang.github.io/rfcs/2145-type-privacy.html. struct PrivTy; trait PrivTr {} diff --git a/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr b/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr index a433cebbbc0..413f7f781cd 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr @@ -1,5 +1,5 @@ error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:19:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:24:1 | LL | trait PrivTr {} | ------------ `PrivTr` declared as private @@ -7,8 +7,26 @@ LL | trait PrivTr {} LL | pub struct S | ^^^^^^^^^^^^ can't leak private trait +warning: trait `PrivTr` is more private than the item `S` + | +note: struct `S` is reachable at visibility `pub` + --> $DIR/where-pub-type-impls-priv-trait.rs:24:1 + | +LL | pub struct S + | ^^^^^^^^^^^^ +note: but trait `PrivTr` is only usable at visibility `pub(crate)` + --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/where-pub-type-impls-priv-trait.rs:7:9 + | +LL | #![warn(private_bounds)] + | ^^^^^^^^^^^^^^ + error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:26:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:31:1 | LL | trait PrivTr {} | ------------ `PrivTr` declared as private @@ -16,8 +34,21 @@ LL | trait PrivTr {} LL | pub enum E | ^^^^^^^^^^ can't leak private trait +warning: trait `PrivTr` is more private than the item `E` + | +note: enum `E` is reachable at visibility `pub` + --> $DIR/where-pub-type-impls-priv-trait.rs:31:1 + | +LL | pub enum E + | ^^^^^^^^^^ +note: but trait `PrivTr` is only usable at visibility `pub(crate)` + --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ + error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:33:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:38:1 | LL | trait PrivTr {} | ------------ `PrivTr` declared as private @@ -28,8 +59,24 @@ LL | | where LL | | PubTy: PrivTr | |_________________^ can't leak private trait +warning: trait `PrivTr` is more private than the item `f` + | +note: function `f` is reachable at visibility `pub` + --> $DIR/where-pub-type-impls-priv-trait.rs:38:1 + | +LL | / pub fn f() +LL | | +LL | | where +LL | | PubTy: PrivTr + | |_________________^ +note: but trait `PrivTr` is only usable at visibility `pub(crate)` + --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ + error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:40:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:45:1 | LL | trait PrivTr {} | ------------ `PrivTr` declared as private @@ -37,8 +84,21 @@ LL | trait PrivTr {} LL | impl S | ^^^^^^ can't leak private trait +warning: trait `PrivTr` is more private than the item `S` + | +note: implementation `S` is reachable at visibility `pub` + --> $DIR/where-pub-type-impls-priv-trait.rs:45:1 + | +LL | impl S + | ^^^^^^ +note: but trait `PrivTr` is only usable at visibility `pub(crate)` + --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ + error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:45:5 + --> $DIR/where-pub-type-impls-priv-trait.rs:50:5 | LL | trait PrivTr {} | ------------ `PrivTr` declared as private @@ -49,6 +109,22 @@ LL | | where LL | | PubTy: PrivTr | |_____________________^ can't leak private trait -error: aborting due to 5 previous errors +warning: trait `PrivTr` is more private than the item `S::f` + | +note: associated function `S::f` is reachable at visibility `pub` + --> $DIR/where-pub-type-impls-priv-trait.rs:50:5 + | +LL | / pub fn f() +LL | | +LL | | where +LL | | PubTy: PrivTr + | |_____________________^ +note: but trait `PrivTr` is only usable at visibility `pub(crate)` + --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 + | +LL | trait PrivTr {} + | ^^^^^^^^^^^^ + +error: aborting due to 5 previous errors; 5 warnings emitted For more information about this error, try `rustc --explain E0445`. |