diff --git a/compiler/rustc_privacy/messages.ftl b/compiler/rustc_privacy/messages.ftl index 6f51981cf09dd..b91e0d18a804f 100644 --- a/compiler/rustc_privacy/messages.ftl +++ b/compiler/rustc_privacy/messages.ftl @@ -18,7 +18,7 @@ privacy_private_in_public_lint = }) privacy_private_interface_or_bounds_lint = {$ty_kind} `{$ty_descr}` is more private than the item `{$item_descr}` - .item_note = {$item_kind} `{$item_descr}` is reachable at visibility `{$item_vis_descr}` + .item_label = {$item_kind} `{$item_descr}` is reachable at visibility `{$item_vis_descr}` .ty_note = but {$ty_kind} `{$ty_descr}` is only usable at visibility `{$ty_vis_descr}` privacy_report_effective_visibility = {$descr} diff --git a/compiler/rustc_privacy/src/errors.rs b/compiler/rustc_privacy/src/errors.rs index 67689b5e71304..da18f0c82682e 100644 --- a/compiler/rustc_privacy/src/errors.rs +++ b/compiler/rustc_privacy/src/errors.rs @@ -116,7 +116,7 @@ pub struct UnnameableTypesLint<'a> { #[derive(LintDiagnostic)] #[diag(privacy_private_interface_or_bounds_lint)] pub struct PrivateInterfacesOrBoundsLint<'a> { - #[note(privacy_item_note)] + #[label(privacy_item_label)] pub item_span: Span, pub item_kind: &'a str, pub item_descr: DiagnosticArgFromDisplay<'a>, diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 3841beb733fd6..c3e8d45d20152 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -1865,9 +1865,10 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> { } else { lint::builtin::PRIVATE_BOUNDS }; - self.tcx.emit_lint( + self.tcx.emit_spanned_lint( lint, hir_id, + span, PrivateInterfacesOrBoundsLint { item_span: span, item_kind: self.tcx.def_descr(self.item_def_id.to_def_id()), diff --git a/tests/ui/associated-inherent-types/private-in-public.rs b/tests/ui/associated-inherent-types/private-in-public.rs index 33b84fc9506b2..e9e189f95c906 100644 --- a/tests/ui/associated-inherent-types/private-in-public.rs +++ b/tests/ui/associated-inherent-types/private-in-public.rs @@ -12,12 +12,15 @@ pub type PubAlias0 = PubTy::PrivAssocTy; //~^ ERROR private associated type `PubTy::PrivAssocTy` in public interface (error E0446) //~| WARNING this was previously accepted +//~| WARNING associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0` pub type PubAlias1 = PrivTy::PubAssocTy; //~^ ERROR private type `PrivTy` in public interface (error E0446) //~| WARNING this was previously accepted +//~| WARNING type `PrivTy` is more private than the item `PubAlias1` pub type PubAlias2 = PubTy::PubAssocTy; //~^ ERROR private type `PrivTy` in public interface (error E0446) //~| WARNING this was previously accepted +//~| WARNING type `PrivTy` is more private than the item `PubAlias2` pub struct PubTy; impl PubTy { diff --git a/tests/ui/associated-inherent-types/private-in-public.stderr b/tests/ui/associated-inherent-types/private-in-public.stderr index d40db83707bbb..65d187c1bcdfb 100644 --- a/tests/ui/associated-inherent-types/private-in-public.stderr +++ b/tests/ui/associated-inherent-types/private-in-public.stderr @@ -13,14 +13,13 @@ 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; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ type alias `PubAlias0` is reachable at visibility `pub` + | note: but associated type `PubTy::PrivAssocTy` is only usable at visibility `pub(crate)` - --> $DIR/private-in-public.rs:24:5 + --> $DIR/private-in-public.rs:27:5 | LL | type PrivAssocTy = (); | ^^^^^^^^^^^^^^^^ @@ -31,7 +30,7 @@ LL | #![warn(private_interfaces)] | ^^^^^^^^^^^^^^^^^^ error: private type `PrivTy` in public interface (error E0446) - --> $DIR/private-in-public.rs:15:1 + --> $DIR/private-in-public.rs:16:1 | LL | pub type PubAlias1 = PrivTy::PubAssocTy; | ^^^^^^^^^^^^^^^^^^ @@ -40,20 +39,19 @@ LL | pub type PubAlias1 = PrivTy::PubAssocTy; = note: for more information, see issue #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 + --> $DIR/private-in-public.rs:16:1 | LL | pub type PubAlias1 = PrivTy::PubAssocTy; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ type alias `PubAlias1` is reachable at visibility `pub` + | note: but type `PrivTy` is only usable at visibility `pub(crate)` - --> $DIR/private-in-public.rs:28:1 + --> $DIR/private-in-public.rs:31:1 | LL | struct PrivTy; | ^^^^^^^^^^^^^ error: private type `PrivTy` in public interface (error E0446) - --> $DIR/private-in-public.rs:18:1 + --> $DIR/private-in-public.rs:20:1 | LL | pub type PubAlias2 = PubTy::PubAssocTy; | ^^^^^^^^^^^^^^^^^^ @@ -62,14 +60,13 @@ LL | pub type PubAlias2 = PubTy::PubAssocTy; = note: for more information, see issue #34537 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 + --> $DIR/private-in-public.rs:20:1 | LL | pub type PubAlias2 = PubTy::PubAssocTy; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ type alias `PubAlias2` is reachable at visibility `pub` + | note: but type `PrivTy` is only usable at visibility `pub(crate)` - --> $DIR/private-in-public.rs:28:1 + --> $DIR/private-in-public.rs:31:1 | LL | struct PrivTy; | ^^^^^^^^^^^^^ 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 5c43213e898a0..e5464a4253f0b 100644 --- a/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs +++ b/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs @@ -21,6 +21,7 @@ where { type AssocTy = Const<{ my_const_fn(U) }>; //~^ ERROR private type + //~| WARNING type `fn(u8) -> u8 {my_const_fn}` is more private than the item ` as Trait>::AssocTy` fn assoc_fn() -> Self::AssocTy { Const } 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 465621619b4d4..16fae6b5c637e 100644 --- a/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr +++ b/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr @@ -8,14 +8,13 @@ LL | const fn my_const_fn(val: u8) -> u8 { | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private warning: type `fn(u8) -> u8 {my_const_fn}` is more private than the item ` as Trait>::AssocTy` - | -note: associated type ` as Trait>::AssocTy` is reachable at visibility `pub` --> $DIR/eval-privacy.rs:22:5 | LL | type AssocTy = Const<{ my_const_fn(U) }>; - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ associated type ` as Trait>::AssocTy` is reachable at visibility `pub` + | note: but type `fn(u8) -> u8 {my_const_fn}` is only usable at visibility `pub(crate)` - --> $DIR/eval-privacy.rs:29:1 + --> $DIR/eval-privacy.rs:30:1 | LL | const fn my_const_fn(val: u8) -> u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/error-codes/E0445.rs b/tests/ui/error-codes/E0445.rs index 30c222ae6f21d..9f29c81673e5b 100644 --- a/tests/ui/error-codes/E0445.rs +++ b/tests/ui/error-codes/E0445.rs @@ -12,9 +12,12 @@ trait Foo { pub trait Bar : Foo {} //~^ ERROR private trait `Foo` in public interface [E0445] +//~| WARNING trait `Foo` is more private than the item `Bar` pub struct Bar2(pub T); //~^ ERROR private trait `Foo` in public interface [E0445] +//~| WARNING trait `Foo` is more private than the item `Bar2` pub fn foo (t: T) {} //~^ ERROR private trait `Foo` in public interface [E0445] +//~| WARNING trait `Foo` is more private than the item `foo` fn main() {} diff --git a/tests/ui/error-codes/E0445.stderr b/tests/ui/error-codes/E0445.stderr index ba2c21485ef9d..4f940868ff905 100644 --- a/tests/ui/error-codes/E0445.stderr +++ b/tests/ui/error-codes/E0445.stderr @@ -8,12 +8,11 @@ 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:13:1 | LL | pub trait Bar : Foo {} - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ trait `Bar` is reachable at visibility `pub` + | note: but trait `Foo` is only usable at visibility `pub(crate)` --> $DIR/E0445.rs:9:1 | @@ -26,7 +25,7 @@ LL | #[warn(private_bounds)] | ^^^^^^^^^^^^^^ error[E0445]: private trait `Foo` in public interface - --> $DIR/E0445.rs:15:1 + --> $DIR/E0445.rs:16:1 | LL | trait Foo { | --------- `Foo` declared as private @@ -35,12 +34,11 @@ LL | pub struct Bar2(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:15:1 + --> $DIR/E0445.rs:16:1 | LL | pub struct Bar2(pub T); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ struct `Bar2` is reachable at visibility `pub` + | note: but trait `Foo` is only usable at visibility `pub(crate)` --> $DIR/E0445.rs:9:1 | @@ -48,7 +46,7 @@ LL | trait Foo { | ^^^^^^^^^ error[E0445]: private trait `Foo` in public interface - --> $DIR/E0445.rs:17:1 + --> $DIR/E0445.rs:19:1 | LL | trait Foo { | --------- `Foo` declared as private @@ -57,12 +55,11 @@ LL | pub fn foo (t: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait warning: trait `Foo` is more private than the item `foo` - | -note: function `foo` is reachable at visibility `pub` - --> $DIR/E0445.rs:17:1 + --> $DIR/E0445.rs:19:1 | LL | pub fn foo (t: T) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ function `foo` is reachable at visibility `pub` + | note: but trait `Foo` is only usable at visibility `pub(crate)` --> $DIR/E0445.rs:9:1 | diff --git a/tests/ui/issues/issue-18389.rs b/tests/ui/issues/issue-18389.rs index 0af693c4e0fe2..05a5decf4629c 100644 --- a/tests/ui/issues/issue-18389.rs +++ b/tests/ui/issues/issue-18389.rs @@ -13,6 +13,7 @@ trait Private { } pub trait Public: Private< //~^ ERROR private trait `Private<::P, ::R>` in public interface +//~| WARNING trait `Private<::P, ::R>` is more private than the item `Public` ::P, ::R > { diff --git a/tests/ui/issues/issue-18389.stderr b/tests/ui/issues/issue-18389.stderr index 6b78151c60682..18ffc4177d718 100644 --- a/tests/ui/issues/issue-18389.stderr +++ b/tests/ui/issues/issue-18389.stderr @@ -6,22 +6,23 @@ LL | trait Private { ... LL | / pub trait Public: Private< LL | | +LL | | LL | | ::P, LL | | ::R LL | | > { | |_^ can't leak private trait warning: trait `Private<::P, ::R>` is more private than the item `Public` - | -note: trait `Public` is reachable at visibility `pub` --> $DIR/issue-18389.rs:14:1 | LL | / pub trait Public: Private< LL | | +LL | | LL | | ::P, LL | | ::R LL | | > { - | |_^ + | |_^ trait `Public` is reachable at visibility `pub` + | note: but trait `Private<::P, ::R>` is only usable at visibility `pub(crate)` --> $DIR/issue-18389.rs:11:1 | diff --git a/tests/ui/privacy/private-in-public-non-principal.rs b/tests/ui/privacy/private-in-public-non-principal.rs index 9ae7512c5092d..a2284c9302742 100644 --- a/tests/ui/privacy/private-in-public-non-principal.rs +++ b/tests/ui/privacy/private-in-public-non-principal.rs @@ -13,6 +13,7 @@ auto trait PrivNonPrincipal {} pub fn leak_dyn_nonprincipal() -> Box { loop {} } //~^ WARN private trait `PrivNonPrincipal` in public interface //~| WARN this was previously accepted +//~| ERROR trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal` #[deny(missing_docs)] fn container() { diff --git a/tests/ui/privacy/private-in-public-non-principal.stderr b/tests/ui/privacy/private-in-public-non-principal.stderr index 9fc12affe4bfb..1387f59cbde12 100644 --- a/tests/ui/privacy/private-in-public-non-principal.stderr +++ b/tests/ui/privacy/private-in-public-non-principal.stderr @@ -9,12 +9,11 @@ LL | pub fn leak_dyn_nonprincipal() -> Box = 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 { loop {} } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `leak_dyn_nonprincipal` is reachable at visibility `pub` + | note: but trait `PrivNonPrincipal` is only usable at visibility `pub(crate)` --> $DIR/private-in-public-non-principal.rs:11:1 | @@ -27,13 +26,13 @@ LL | #![deny(private_interfaces)] | ^^^^^^^^^^^^^^^^^^ error: missing documentation for an associated function - --> $DIR/private-in-public-non-principal.rs:20:9 + --> $DIR/private-in-public-non-principal.rs:21:9 | LL | pub fn check_doc_lint() {} | ^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/private-in-public-non-principal.rs:17:8 + --> $DIR/private-in-public-non-principal.rs:18:8 | LL | #[deny(missing_docs)] | ^^^^^^^^^^^^ diff --git a/tests/ui/privacy/where-priv-type.rs b/tests/ui/privacy/where-priv-type.rs index 468d6e98a74d9..2e0a6b3e72cc1 100644 --- a/tests/ui/privacy/where-priv-type.rs +++ b/tests/ui/privacy/where-priv-type.rs @@ -25,6 +25,7 @@ impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; } pub struct S //~^ WARNING private type `PrivTy` in public interface //~| WARNING hard error +//~| WARNING type `PrivTy` is more private than the item `S` where PrivTy: {} @@ -33,6 +34,7 @@ where pub enum E //~^ WARNING private type `PrivTy` in public interface //~| WARNING hard error +//~| WARNING type `PrivTy` is more private than the item `E` where PrivTy: {} @@ -41,6 +43,7 @@ where pub fn f() //~^ WARNING private type `PrivTy` in public interface //~| WARNING hard error +//~| WARNING type `PrivTy` is more private than the item `f` where PrivTy: {} @@ -48,12 +51,14 @@ where impl S //~^ ERROR private type `PrivTy` in public interface +//~| WARNING type `PrivTy` is more private than the item `S` where PrivTy: { pub fn f() //~^ WARNING private type `PrivTy` in public interface //~| WARNING hard error + //~| WARNING type `PrivTy` is more private than the item `S::f` where PrivTy: {} @@ -85,6 +90,7 @@ where { type AssocTy = Const<{ my_const_fn(U) }>; //~^ ERROR private type + //~| WARNING type `fn(u8) -> u8 {my_const_fn}` is more private than the item ` as Trait>::AssocTy` fn assoc_fn() -> Self::AssocTy { Const } diff --git a/tests/ui/privacy/where-priv-type.stderr b/tests/ui/privacy/where-priv-type.stderr index 2830fa6cd442c..d6baf22b3fbc0 100644 --- a/tests/ui/privacy/where-priv-type.stderr +++ b/tests/ui/privacy/where-priv-type.stderr @@ -9,12 +9,11 @@ LL | pub struct S = 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 - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ struct `S` is reachable at visibility `pub` + | note: but type `PrivTy` is only usable at visibility `pub(crate)` --> $DIR/where-priv-type.rs:15:1 | @@ -27,7 +26,7 @@ LL | #![warn(private_bounds)] | ^^^^^^^^^^^^^^ warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:33:1 + --> $DIR/where-priv-type.rs:34:1 | LL | pub enum E | ^^^^^^^^^^ @@ -36,12 +35,11 @@ LL | pub enum E = note: for more information, see issue #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 + --> $DIR/where-priv-type.rs:34:1 | LL | pub enum E - | ^^^^^^^^^^ + | ^^^^^^^^^^ enum `E` is reachable at visibility `pub` + | note: but type `PrivTy` is only usable at visibility `pub(crate)` --> $DIR/where-priv-type.rs:15:1 | @@ -49,11 +47,12 @@ LL | struct PrivTy; | ^^^^^^^^^^^^^ warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:41:1 + --> $DIR/where-priv-type.rs:43:1 | LL | / pub fn f() LL | | LL | | +LL | | LL | | where LL | | PrivTy: | |___________^ @@ -62,16 +61,16 @@ LL | | PrivTy: = note: for more information, see issue #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 + --> $DIR/where-priv-type.rs:43:1 | LL | / pub fn f() LL | | LL | | +LL | | LL | | where LL | | PrivTy: - | |___________^ + | |___________^ function `f` is reachable at visibility `pub` + | note: but type `PrivTy` is only usable at visibility `pub(crate)` --> $DIR/where-priv-type.rs:15:1 | @@ -79,7 +78,7 @@ LL | struct PrivTy; | ^^^^^^^^^^^^^ error[E0446]: private type `PrivTy` in public interface - --> $DIR/where-priv-type.rs:49:1 + --> $DIR/where-priv-type.rs:52:1 | LL | struct PrivTy; | ------------- `PrivTy` declared as private @@ -88,12 +87,11 @@ 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 + --> $DIR/where-priv-type.rs:52:1 | LL | impl S - | ^^^^^^ + | ^^^^^^ implementation `S` is reachable at visibility `pub` + | note: but type `PrivTy` is only usable at visibility `pub(crate)` --> $DIR/where-priv-type.rs:15:1 | @@ -101,11 +99,12 @@ LL | struct PrivTy; | ^^^^^^^^^^^^^ warning: private type `PrivTy` in public interface (error E0446) - --> $DIR/where-priv-type.rs:54:5 + --> $DIR/where-priv-type.rs:58:5 | LL | / pub fn f() LL | | LL | | +LL | | LL | | where LL | | PrivTy: | |_______________^ @@ -114,16 +113,16 @@ LL | | PrivTy: = note: for more information, see issue #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 + --> $DIR/where-priv-type.rs:58:5 | LL | / pub fn f() LL | | LL | | +LL | | LL | | where LL | | PrivTy: - | |_______________^ + | |_______________^ associated function `S::f` is reachable at visibility `pub` + | note: but type `PrivTy` is only usable at visibility `pub(crate)` --> $DIR/where-priv-type.rs:15:1 | @@ -131,7 +130,7 @@ LL | struct PrivTy; | ^^^^^^^^^^^^^ error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface - --> $DIR/where-priv-type.rs:86:5 + --> $DIR/where-priv-type.rs:91:5 | LL | type AssocTy = Const<{ my_const_fn(U) }>; | ^^^^^^^^^^^^ can't leak private type @@ -140,14 +139,13 @@ LL | const fn my_const_fn(val: u8) -> u8 { | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private warning: type `fn(u8) -> u8 {my_const_fn}` is more private than the item ` as Trait>::AssocTy` - | -note: associated type ` as Trait>::AssocTy` is reachable at visibility `pub` - --> $DIR/where-priv-type.rs:86:5 + --> $DIR/where-priv-type.rs:91:5 | LL | type AssocTy = Const<{ my_const_fn(U) }>; - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ associated type ` as Trait>::AssocTy` is reachable at visibility `pub` + | note: but type `fn(u8) -> u8 {my_const_fn}` is only usable at visibility `pub(crate)` - --> $DIR/where-priv-type.rs:93:1 + --> $DIR/where-priv-type.rs:99:1 | LL | const fn my_const_fn(val: u8) -> u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 35e33bcb3b715..c59fdb7c7a960 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.rs +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.rs @@ -23,6 +23,7 @@ impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; } pub struct S //~^ ERROR private trait `PrivTr` in public interface +//~| WARNING trait `PrivTr` is more private than the item `S` where PubTy: PrivTr {} @@ -30,6 +31,7 @@ where pub enum E //~^ ERROR private trait `PrivTr` in public interface +//~| WARNING trait `PrivTr` is more private than the item `E` where PubTy: PrivTr {} @@ -37,6 +39,7 @@ where pub fn f() //~^ ERROR private trait `PrivTr` in public interface +//~| WARNING trait `PrivTr` is more private than the item `f` where PubTy: PrivTr {} @@ -44,11 +47,13 @@ where impl S //~^ ERROR private trait `PrivTr` in public interface +//~| WARNING trait `PrivTr` is more private than the item `S` where PubTy: PrivTr { pub fn f() //~^ ERROR private trait `PrivTr` in public interface + //~| WARNING trait `PrivTr` is more private than the item `S::f` where PubTy: 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 413f7f781cd85..e2d7ce4469242 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr @@ -8,12 +8,11 @@ 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 - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ struct `S` is reachable at visibility `pub` + | note: but trait `PrivTr` is only usable at visibility `pub(crate)` --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 | @@ -26,7 +25,7 @@ LL | #![warn(private_bounds)] | ^^^^^^^^^^^^^^ error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:31:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:32:1 | LL | trait PrivTr {} | ------------ `PrivTr` declared as private @@ -35,12 +34,11 @@ 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 + --> $DIR/where-pub-type-impls-priv-trait.rs:32:1 | LL | pub enum E - | ^^^^^^^^^^ + | ^^^^^^^^^^ enum `E` is reachable at visibility `pub` + | note: but trait `PrivTr` is only usable at visibility `pub(crate)` --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 | @@ -48,27 +46,28 @@ LL | trait PrivTr {} | ^^^^^^^^^^^^ error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:38:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:40:1 | LL | trait PrivTr {} | ------------ `PrivTr` declared as private ... LL | / pub fn f() LL | | +LL | | 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 + --> $DIR/where-pub-type-impls-priv-trait.rs:40:1 | LL | / pub fn f() LL | | +LL | | LL | | where LL | | PubTy: PrivTr - | |_________________^ + | |_________________^ function `f` is reachable at visibility `pub` + | note: but trait `PrivTr` is only usable at visibility `pub(crate)` --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 | @@ -76,7 +75,7 @@ LL | trait PrivTr {} | ^^^^^^^^^^^^ error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:45:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:48:1 | LL | trait PrivTr {} | ------------ `PrivTr` declared as private @@ -85,12 +84,11 @@ 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 + --> $DIR/where-pub-type-impls-priv-trait.rs:48:1 | LL | impl S - | ^^^^^^ + | ^^^^^^ implementation `S` is reachable at visibility `pub` + | note: but trait `PrivTr` is only usable at visibility `pub(crate)` --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 | @@ -98,27 +96,28 @@ LL | trait PrivTr {} | ^^^^^^^^^^^^ error[E0445]: private trait `PrivTr` in public interface - --> $DIR/where-pub-type-impls-priv-trait.rs:50:5 + --> $DIR/where-pub-type-impls-priv-trait.rs:54:5 | LL | trait PrivTr {} | ------------ `PrivTr` declared as private ... LL | / pub fn f() LL | | +LL | | LL | | where LL | | PubTy: PrivTr | |_____________________^ can't leak private trait 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 + --> $DIR/where-pub-type-impls-priv-trait.rs:54:5 | LL | / pub fn f() LL | | +LL | | LL | | where LL | | PubTy: PrivTr - | |_____________________^ + | |_____________________^ associated function `S::f` is reachable at visibility `pub` + | note: but trait `PrivTr` is only usable at visibility `pub(crate)` --> $DIR/where-pub-type-impls-priv-trait.rs:14:1 | 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 bd8f6585f4820..cdeea6224b208 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 @@ -27,14 +27,17 @@ pub struct Shell { pub type Helix_pomatia = Shell; //~^ ERROR private type `Snail` in public interface +//~| WARNING type `Snail` is more private than the item `Helix_pomatia` //~| NOTE can't leak private type //~| NOTE type alias `Helix_pomatia` is reachable at visibility `pub` pub type Dermochelys_coriacea = Shell; //~^ ERROR crate-private type `Turtle` in public interface +//~| WARNING type `Turtle` is more private than the item `Dermochelys_coriacea` //~| NOTE can't leak crate-private type //~| NOTE type alias `Dermochelys_coriacea` is reachable at visibility `pub` pub type Testudo_graeca = Shell; //~^ ERROR private type `Tortoise` in public interface +//~| WARNING type `Tortoise` is more private than the item `Testudo_graeca` //~| NOTE can't leak private type //~| NOTE type alias `Testudo_graeca` is reachable at visibility `pub` 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 5ebda47558ca4..20e51e1901ff2 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 @@ -8,12 +8,11 @@ LL | pub type Helix_pomatia = Shell; | ^^^^^^^^^^^^^^^^^^^^^^ 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:28:1 | LL | pub type Helix_pomatia = Shell; - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ type alias `Helix_pomatia` is reachable at visibility `pub` + | note: but type `Snail` is only usable at visibility `pub(crate)` --> $DIR/issue-33174-restricted-type-in-public-interface.rs:10:1 | @@ -26,7 +25,7 @@ LL | #![warn(private_interfaces)] | ^^^^^^^^^^^^^^^^^^ error[E0446]: crate-private type `Turtle` in public interface - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:32:1 + --> $DIR/issue-33174-restricted-type-in-public-interface.rs:33:1 | LL | pub(super) struct Turtle; | ------------------------ `Turtle` declared as crate-private @@ -35,12 +34,11 @@ LL | pub type Dermochelys_coriacea = Shell; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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:32:1 + --> $DIR/issue-33174-restricted-type-in-public-interface.rs:33:1 | LL | pub type Dermochelys_coriacea = Shell; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type alias `Dermochelys_coriacea` is reachable at visibility `pub` + | note: but type `Turtle` is only usable at visibility `pub(crate)` --> $DIR/issue-33174-restricted-type-in-public-interface.rs:15:5 | @@ -48,7 +46,7 @@ LL | pub(super) struct Turtle; | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0446]: private type `Tortoise` in public interface - --> $DIR/issue-33174-restricted-type-in-public-interface.rs:36:1 + --> $DIR/issue-33174-restricted-type-in-public-interface.rs:38:1 | LL | struct Tortoise; | --------------- `Tortoise` declared as private @@ -57,12 +55,11 @@ LL | pub type Testudo_graeca = Shell; | ^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type 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:36:1 + --> $DIR/issue-33174-restricted-type-in-public-interface.rs:38:1 | LL | pub type Testudo_graeca = Shell; - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ type alias `Testudo_graeca` is reachable at visibility `pub` + | note: but type `Tortoise` is only usable at visibility `pub(crate)` --> $DIR/issue-33174-restricted-type-in-public-interface.rs:20:1 |