about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-06-11 22:18:23 +0000
committerbors <bors@rust-lang.org>2023-06-11 22:18:23 +0000
commit77dba225c1048e5585b2cdefb7f8588bd2d2741b (patch)
tree89b81f60a07b914d6d38b5c12c176695b6175bf2 /tests
parent37998ab508d5d9fa0d465d7b535dc673087dda8f (diff)
parent6d46382f6f0688df0fc5c67386f86ccd6fdb975f (diff)
downloadrust-77dba225c1048e5585b2cdefb7f8588bd2d2741b.tar.gz
rust-77dba225c1048e5585b2cdefb7f8588bd2d2741b.zip
Auto merge of #111801 - Bryanskiy:lints1, r=petrochenkov
Private-in-public lints implementation

Next part of RFC https://github.com/rust-lang/rust/issues/48054.

r? `@petrochenkov`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/associated-inherent-types/private-in-public.rs5
-rw-r--r--tests/ui/associated-inherent-types/private-in-public.stderr52
-rw-r--r--tests/ui/const-generics/generic_const_exprs/eval-privacy.rs6
-rw-r--r--tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr22
-rw-r--r--tests/ui/error-codes/E0445.rs7
-rw-r--r--tests/ui/error-codes/E0445.stderr52
-rw-r--r--tests/ui/issues/issue-18389.rs6
-rw-r--r--tests/ui/issues/issue-18389.stderr26
-rw-r--r--tests/ui/privacy/private-in-public-non-principal.rs6
-rw-r--r--tests/ui/privacy/private-in-public-non-principal.stderr26
-rw-r--r--tests/ui/privacy/private-inferred-type-1.rs10
-rw-r--r--tests/ui/privacy/private-inferred-type-1.stderr18
-rw-r--r--tests/ui/privacy/unnameable_types.rs30
-rw-r--r--tests/ui/privacy/unnameable_types.stderr38
-rw-r--r--tests/ui/privacy/where-priv-type.rs6
-rw-r--r--tests/ui/privacy/where-priv-type.stderr110
-rw-r--r--tests/ui/privacy/where-pub-type-impls-priv-trait.rs5
-rw-r--r--tests/ui/privacy/where-pub-type-impls-priv-trait.stderr88
-rw-r--r--tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs12
-rw-r--r--tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr52
20 files changed, 541 insertions, 36 deletions
diff --git a/tests/ui/associated-inherent-types/private-in-public.rs b/tests/ui/associated-inherent-types/private-in-public.rs
index a4b372537c7..44a20a79ad6 100644
--- a/tests/ui/associated-inherent-types/private-in-public.rs
+++ b/tests/ui/associated-inherent-types/private-in-public.rs
@@ -3,6 +3,11 @@
 #![crate_type = "lib"]
 
 #![deny(private_in_public)]
+#![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.
 
 pub type PubAlias0 = PubTy::PrivAssocTy;
 //~^ ERROR private associated type `PubTy::PrivAssocTy` in public interface (error E0446)
diff --git a/tests/ui/associated-inherent-types/private-in-public.stderr b/tests/ui/associated-inherent-types/private-in-public.stderr
index f0a64e96179..d40db83707b 100644
--- a/tests/ui/associated-inherent-types/private-in-public.stderr
+++ b/tests/ui/associated-inherent-types/private-in-public.stderr
@@ -1,5 +1,5 @@
 error: private associated type `PubTy::PrivAssocTy` in public interface (error E0446)
-  --> $DIR/private-in-public.rs:7:1
+  --> $DIR/private-in-public.rs:12:1
    |
 LL | pub type PubAlias0 = PubTy::PrivAssocTy;
    | ^^^^^^^^^^^^^^^^^^
@@ -12,8 +12,26 @@ note: the lint level is defined here
 LL | #![deny(private_in_public)]
    |         ^^^^^^^^^^^^^^^^^
 
+warning: associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0`
+   |
+note: type alias `PubAlias0` is reachable at visibility `pub`
+  --> $DIR/private-in-public.rs:12:1
+   |
+LL | pub type PubAlias0 = PubTy::PrivAssocTy;
+   | ^^^^^^^^^^^^^^^^^^
+note: but associated type `PubTy::PrivAssocTy` is only usable at visibility `pub(crate)`
+  --> $DIR/private-in-public.rs:24:5
+   |
+LL |     type PrivAssocTy = ();
+   |     ^^^^^^^^^^^^^^^^
+note: the lint level is defined here
+  --> $DIR/private-in-public.rs:6:9
+   |
+LL | #![warn(private_interfaces)]
+   |         ^^^^^^^^^^^^^^^^^^
+
 error: private type `PrivTy` in public interface (error E0446)
-  --> $DIR/private-in-public.rs:10:1
+  --> $DIR/private-in-public.rs:15:1
    |
 LL | pub type PubAlias1 = PrivTy::PubAssocTy;
    | ^^^^^^^^^^^^^^^^^^
@@ -21,8 +39,21 @@ LL | pub type PubAlias1 = PrivTy::PubAssocTy;
    = 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 `PubAlias1`
+   |
+note: type alias `PubAlias1` is reachable at visibility `pub`
+  --> $DIR/private-in-public.rs:15:1
+   |
+LL | pub type PubAlias1 = PrivTy::PubAssocTy;
+   | ^^^^^^^^^^^^^^^^^^
+note: but type `PrivTy` is only usable at visibility `pub(crate)`
+  --> $DIR/private-in-public.rs:28:1
+   |
+LL | struct PrivTy;
+   | ^^^^^^^^^^^^^
+
 error: private type `PrivTy` in public interface (error E0446)
-  --> $DIR/private-in-public.rs:13:1
+  --> $DIR/private-in-public.rs:18:1
    |
 LL | pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>;
    | ^^^^^^^^^^^^^^^^^^
@@ -30,5 +61,18 @@ LL | pub type PubAlias2 = PubTy::PubAssocTy<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>
 
-error: aborting due to 3 previous errors
+warning: type `PrivTy` is more private than the item `PubAlias2`
+   |
+note: type alias `PubAlias2` is reachable at visibility `pub`
+  --> $DIR/private-in-public.rs:18:1
+   |
+LL | pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>;
+   | ^^^^^^^^^^^^^^^^^^
+note: but type `PrivTy` is only usable at visibility `pub(crate)`
+  --> $DIR/private-in-public.rs:28:1
+   |
+LL | struct PrivTy;
+   | ^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors; 3 warnings emitted
 
diff --git a/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs b/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs
index 8023b998a40..96b769699cc 100644
--- a/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs
+++ b/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs
@@ -2,6 +2,12 @@
 #![feature(generic_const_exprs)]
 #![allow(incomplete_features)]
 
+#![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.
+
 pub struct Const<const U: u8>;
 
 pub trait Trait {
diff --git a/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr b/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr
index 2d9de8805bb..465621619b4 100644
--- a/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr
+++ b/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr
@@ -1,5 +1,5 @@
 error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface
-  --> $DIR/eval-privacy.rs:16:5
+  --> $DIR/eval-privacy.rs:22:5
    |
 LL |     type AssocTy = Const<{ my_const_fn(U) }>;
    |     ^^^^^^^^^^^^ can't leak private type
@@ -7,6 +7,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 previous error
+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/eval-privacy.rs:22: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/eval-privacy.rs:29:1
+   |
+LL | const fn my_const_fn(val: u8) -> u8 {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: the lint level is defined here
+  --> $DIR/eval-privacy.rs:5:9
+   |
+LL | #![warn(private_interfaces)]
+   |         ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error; 1 warning emitted
 
 For more information about this error, try `rustc --explain E0446`.
diff --git a/tests/ui/error-codes/E0445.rs b/tests/ui/error-codes/E0445.rs
index a9a3aee2500..f5f35fb8a4d 100644
--- a/tests/ui/error-codes/E0445.rs
+++ b/tests/ui/error-codes/E0445.rs
@@ -1,3 +1,10 @@
+#[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.
+
 trait Foo {
     fn dummy(&self) { }
 }
diff --git a/tests/ui/error-codes/E0445.stderr b/tests/ui/error-codes/E0445.stderr
index 23b7a335047..ac3637a8218 100644
--- a/tests/ui/error-codes/E0445.stderr
+++ b/tests/ui/error-codes/E0445.stderr
@@ -1,5 +1,5 @@
 error[E0445]: private trait `Foo` in public interface
-  --> $DIR/E0445.rs:5:1
+  --> $DIR/E0445.rs:12:1
    |
 LL | trait Foo {
    | --------- `Foo` declared as private
@@ -7,8 +7,26 @@ LL | trait Foo {
 LL | pub trait Bar : Foo {}
    | ^^^^^^^^^^^^^^^^^^^ can't leak private trait
 
+warning: trait `Foo` is more private than the item `Bar`
+   |
+note: trait `Bar` is reachable at visibility `pub`
+  --> $DIR/E0445.rs:12:1
+   |
+LL | pub trait Bar : Foo {}
+   | ^^^^^^^^^^^^^^^^^^^
+note: but trait `Foo` is only usable at visibility `pub(crate)`
+  --> $DIR/E0445.rs:8:1
+   |
+LL | trait Foo {
+   | ^^^^^^^^^
+note: the lint level is defined here
+  --> $DIR/E0445.rs:1:8
+   |
+LL | #[warn(private_bounds)]
+   |        ^^^^^^^^^^^^^^
+
 error[E0445]: private trait `Foo` in public interface
-  --> $DIR/E0445.rs:7:1
+  --> $DIR/E0445.rs:14:1
    |
 LL | trait Foo {
    | --------- `Foo` declared as private
@@ -16,8 +34,21 @@ LL | trait Foo {
 LL | pub struct Bar2<T: Foo>(pub T);
    | ^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
 
+warning: trait `Foo` is more private than the item `Bar2`
+   |
+note: struct `Bar2` is reachable at visibility `pub`
+  --> $DIR/E0445.rs:14: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
+   |
+LL | trait Foo {
+   | ^^^^^^^^^
+
 error[E0445]: private trait `Foo` in public interface
-  --> $DIR/E0445.rs:9:1
+  --> $DIR/E0445.rs:16:1
    |
 LL | trait Foo {
    | --------- `Foo` declared as private
@@ -25,6 +56,19 @@ LL | trait Foo {
 LL | pub fn foo<T: Foo> (t: T) {}
    | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
 
-error: aborting due to 3 previous errors
+warning: trait `Foo` is more private than the item `foo`
+   |
+note: function `foo` is reachable at visibility `pub`
+  --> $DIR/E0445.rs:16: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
+   |
+LL | trait Foo {
+   | ^^^^^^^^^
+
+error: aborting due to 3 previous errors; 3 warnings emitted
 
 For more information about this error, try `rustc --explain E0445`.
diff --git a/tests/ui/issues/issue-18389.rs b/tests/ui/issues/issue-18389.rs
index 654dfb63b88..3686afc48af 100644
--- a/tests/ui/issues/issue-18389.rs
+++ b/tests/ui/issues/issue-18389.rs
@@ -1,3 +1,9 @@
+#![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.
+
 use std::any::Any;
 use std::any::TypeId;
 
diff --git a/tests/ui/issues/issue-18389.stderr b/tests/ui/issues/issue-18389.stderr
index 6ce78c45d6e..f9ebde48a45 100644
--- a/tests/ui/issues/issue-18389.stderr
+++ b/tests/ui/issues/issue-18389.stderr
@@ -1,5 +1,5 @@
 error[E0445]: private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface
-  --> $DIR/issue-18389.rs:7:1
+  --> $DIR/issue-18389.rs:13:1
    |
 LL |   trait Private<P, R> {
    |   ------------------- `Private<<Self as Public>::P, <Self as Public>::R>` declared as private
@@ -11,6 +11,28 @@ LL | |     <Self as Public>::R
 LL | | > {
    | |_^ can't leak private trait
 
-error: aborting due to previous error
+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
+   |
+LL | / pub trait Public: Private<
+LL | |
+LL | |     <Self as Public>::P,
+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
+   |
+LL | trait Private<P, R> {
+   | ^^^^^^^^^^^^^^^^^^^
+note: the lint level is defined here
+  --> $DIR/issue-18389.rs:1:9
+   |
+LL | #![warn(private_bounds)]
+   |         ^^^^^^^^^^^^^^
+
+error: aborting due to previous error; 1 warning emitted
 
 For more information about this error, try `rustc --explain E0445`.
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`.
diff --git a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs
index 67f888c5e94..9e4ba80a784 100644
--- a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs
+++ b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs
@@ -1,15 +1,24 @@
 #![allow(non_camel_case_types)] // genus is always capitalized
+#![warn(private_interfaces)]
+//~^ NOTE the lint level is defined here
+
+// 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(crate) struct Snail;
 //~^ NOTE `Snail` declared as private
+//~| NOTE but type `Snail` is only usable at visibility `pub(crate)`
 
 mod sea {
     pub(super) struct Turtle;
     //~^ NOTE `Turtle` declared as crate-private
+    //~| NOTE but type `Turtle` is only usable at visibility `pub(crate)`
 }
 
 struct Tortoise;
 //~^ NOTE `Tortoise` declared as private
+//~| NOTE but type `Tortoise` is only usable at visibility `pub(crate)`
 
 pub struct Shell<T> {
     pub(crate) creature: T,
@@ -18,11 +27,14 @@ pub struct Shell<T> {
 pub type Helix_pomatia = Shell<Snail>;
 //~^ ERROR private type `Snail` in public interface
 //~| NOTE can't leak private type
+//~| NOTE type alias `Helix_pomatia` is reachable at visibility `pub`
 pub type Dermochelys_coriacea = Shell<sea::Turtle>;
 //~^ ERROR crate-private type `Turtle` in public interface
 //~| NOTE can't leak crate-private type
+//~| NOTE type alias `Dermochelys_coriacea` is reachable at visibility `pub`
 pub type Testudo_graeca = Shell<Tortoise>;
 //~^ ERROR private type `Tortoise` in public interface
 //~| NOTE can't leak private type
+//~| NOTE type alias `Testudo_graeca` is reachable at visibility `pub`
 
 fn main() {}
diff --git a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr
index 39d4f5ac8d3..52f67d4cdd5 100644
--- a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr
+++ b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr
@@ -1,5 +1,5 @@
 error[E0446]: private type `Snail` in public interface
-  --> $DIR/issue-33174-restricted-type-in-public-interface.rs:18:1
+  --> $DIR/issue-33174-restricted-type-in-public-interface.rs:27:1
    |
 LL | pub(crate) struct Snail;
    | ----------------------- `Snail` declared as private
@@ -7,8 +7,26 @@ LL | pub(crate) struct Snail;
 LL | pub type Helix_pomatia = Shell<Snail>;
    | ^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
 
+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
+   |
+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
+   |
+LL | pub(crate) struct Snail;
+   | ^^^^^^^^^^^^^^^^^^^^^^^
+note: the lint level is defined here
+  --> $DIR/issue-33174-restricted-type-in-public-interface.rs:2:9
+   |
+LL | #![warn(private_interfaces)]
+   |         ^^^^^^^^^^^^^^^^^^
+
 error[E0446]: crate-private type `Turtle` in public interface
-  --> $DIR/issue-33174-restricted-type-in-public-interface.rs:21:1
+  --> $DIR/issue-33174-restricted-type-in-public-interface.rs:31:1
    |
 LL |     pub(super) struct Turtle;
    |     ------------------------ `Turtle` declared as crate-private
@@ -16,8 +34,21 @@ LL |     pub(super) struct Turtle;
 LL | pub type Dermochelys_coriacea = Shell<sea::Turtle>;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak crate-private type
 
+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
+   |
+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
+   |
+LL |     pub(super) struct Turtle;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^
+
 error[E0446]: private type `Tortoise` in public interface
-  --> $DIR/issue-33174-restricted-type-in-public-interface.rs:24:1
+  --> $DIR/issue-33174-restricted-type-in-public-interface.rs:35:1
    |
 LL | struct Tortoise;
    | --------------- `Tortoise` declared as private
@@ -25,6 +56,19 @@ LL | struct Tortoise;
 LL | pub type Testudo_graeca = Shell<Tortoise>;
    | ^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
 
-error: aborting due to 3 previous errors
+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
+   |
+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
+   |
+LL | struct Tortoise;
+   | ^^^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors; 3 warnings emitted
 
 For more information about this error, try `rustc --explain E0446`.