From 2390abed22be00a55a4c9326d09c1a9bd0c47d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ml=C3=A1dek?= Date: Wed, 16 Jul 2025 17:49:47 +0200 Subject: [PATCH] tests: cover more `exported_private_dependencies` cases --- .../pub-priv-dep/auxiliary/priv_dep.rs | 7 + tests/ui/privacy/pub-priv-dep/pub-priv1.rs | 76 ++++++- .../ui/privacy/pub-priv-dep/pub-priv1.stderr | 186 ++++++++++++++++-- 3 files changed, 250 insertions(+), 19 deletions(-) diff --git a/tests/ui/privacy/pub-priv-dep/auxiliary/priv_dep.rs b/tests/ui/privacy/pub-priv-dep/auxiliary/priv_dep.rs index 4eeecdc056972..d389f8c861a41 100644 --- a/tests/ui/privacy/pub-priv-dep/auxiliary/priv_dep.rs +++ b/tests/ui/privacy/pub-priv-dep/auxiliary/priv_dep.rs @@ -1,5 +1,6 @@ pub struct OtherType; pub trait OtherTrait {} +impl OtherTrait for OtherType {} #[macro_export] macro_rules! m { @@ -9,3 +10,9 @@ macro_rules! m { pub enum E { V1 } + +struct PrivType; + +pub type Unit = (); +pub type PubPub = OtherType; +pub type PubPriv = PrivType; diff --git a/tests/ui/privacy/pub-priv-dep/pub-priv1.rs b/tests/ui/privacy/pub-priv-dep/pub-priv1.rs index 192ca0db8bd41..e537e1bb5ef31 100644 --- a/tests/ui/privacy/pub-priv-dep/pub-priv1.rs +++ b/tests/ui/privacy/pub-priv-dep/pub-priv1.rs @@ -32,6 +32,33 @@ pub struct PublicType { pub other_field: PubType, // Type from public dependency - this is fine } +pub struct PublicTuple( + pub OtherType, + //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface [exported_private_dependencies] + OtherType, + PubType, +); + +pub enum PublicEnum { + OtherType, + ActualOtherType(OtherType, PubType), + //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface [exported_private_dependencies] + ActualOtherTypeStruct { + field: OtherType, + //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface [exported_private_dependencies] + pub other_field: PubType, + }, +} + +pub struct PublicGenericType(pub T, U); +pub type ReexportedPublicGeneric = PublicGenericType; +//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface +pub type ReexportedPrivateGeneric = PublicGenericType<(), OtherType>; +//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface + +pub struct PublicGenericBoundedType(T); +//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface + impl PublicType { pub fn pub_fn_param(param: OtherType) {} //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface @@ -44,8 +71,21 @@ impl PublicType { pub trait MyPubTrait { type Foo: OtherTrait; + //~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface + + fn required_impl_trait() -> impl OtherTrait; + //~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface + + fn provided_impl_trait() -> impl OtherTrait { OtherType } + //~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface + //~| ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface + + fn required_concrete() -> OtherType; + //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface + + fn provided_concrete() -> OtherType { OtherType } + //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface } -//~^^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface pub trait WithSuperTrait: OtherTrait {} //~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface @@ -63,6 +103,12 @@ impl PubLocalTraitWithAssoc for PrivateAssoc { pub fn in_bounds(x: T) { unimplemented!() } //~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface +pub fn private_return_impl_trait() -> impl OtherTrait { OtherType } +//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface + +pub fn private_return() -> OtherType { OtherType } +//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface + pub fn private_in_generic() -> std::num::Saturating { unimplemented!() } //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface @@ -75,6 +121,9 @@ pub const CONST: OtherType = OtherType; pub type Alias = OtherType; //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface +pub type AliasOfAlias = priv_dep::PubPub; +//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface + pub struct PublicWithPrivateImpl; impl OtherTrait for PublicWithPrivateImpl {} @@ -86,6 +135,22 @@ impl PubTraitOnPrivate for OtherType {} //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface //~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface +pub struct PublicWithStdImpl; + +impl From for PublicWithStdImpl { +//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface + fn from(val: OtherType) -> Self { Self } + //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface +} + +impl From for OtherType { + //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface + //~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface + fn from(val: PublicWithStdImpl) -> Self { Self } + //~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface + //~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface +} + pub struct AllowedPrivType { #[allow(exported_private_dependencies)] pub allowed: OtherType, @@ -103,4 +168,13 @@ pub use pm::pm_attr; pub use priv_dep::E::V1; //~^ ERROR variant `V1` from private dependency 'priv_dep' is re-exported +pub use priv_dep::Unit; +//~^ ERROR type alias `Unit` from private dependency 'priv_dep' is re-exported +pub use priv_dep::PubPub; +//~^ ERROR type alias `PubPub` from private dependency 'priv_dep' is re-exported +pub use priv_dep::PubPriv; +//~^ ERROR type alias `PubPriv` from private dependency 'priv_dep' is re-exported +pub use priv_dep::OtherType as Renamed; +//~^ ERROR struct `Renamed` from private dependency 'priv_dep' is re-exported + fn main() {} diff --git a/tests/ui/privacy/pub-priv-dep/pub-priv1.stderr b/tests/ui/privacy/pub-priv-dep/pub-priv1.stderr index 9da47827be4b1..61c948c2817a9 100644 --- a/tests/ui/privacy/pub-priv-dep/pub-priv1.stderr +++ b/tests/ui/privacy/pub-priv-dep/pub-priv1.stderr @@ -11,35 +11,59 @@ LL | #![deny(exported_private_dependencies)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: macro `m` from private dependency 'priv_dep' is re-exported - --> $DIR/pub-priv1.rs:94:9 + --> $DIR/pub-priv1.rs:159:9 | LL | pub use priv_dep::m; | ^^^^^^^^^^^ error: macro `fn_like` from private dependency 'pm' is re-exported - --> $DIR/pub-priv1.rs:96:9 + --> $DIR/pub-priv1.rs:161:9 | LL | pub use pm::fn_like; | ^^^^^^^^^^^ error: derive macro `PmDerive` from private dependency 'pm' is re-exported - --> $DIR/pub-priv1.rs:98:9 + --> $DIR/pub-priv1.rs:163:9 | LL | pub use pm::PmDerive; | ^^^^^^^^^^^^ error: attribute macro `pm_attr` from private dependency 'pm' is re-exported - --> $DIR/pub-priv1.rs:100:9 + --> $DIR/pub-priv1.rs:165:9 | LL | pub use pm::pm_attr; | ^^^^^^^^^^^ error: variant `V1` from private dependency 'priv_dep' is re-exported - --> $DIR/pub-priv1.rs:103:9 + --> $DIR/pub-priv1.rs:168:9 | LL | pub use priv_dep::E::V1; | ^^^^^^^^^^^^^^^ +error: type alias `Unit` from private dependency 'priv_dep' is re-exported + --> $DIR/pub-priv1.rs:171:9 + | +LL | pub use priv_dep::Unit; + | ^^^^^^^^^^^^^^ + +error: type alias `PubPub` from private dependency 'priv_dep' is re-exported + --> $DIR/pub-priv1.rs:173:9 + | +LL | pub use priv_dep::PubPub; + | ^^^^^^^^^^^^^^^^ + +error: type alias `PubPriv` from private dependency 'priv_dep' is re-exported + --> $DIR/pub-priv1.rs:175:9 + | +LL | pub use priv_dep::PubPriv; + | ^^^^^^^^^^^^^^^^^ + +error: struct `Renamed` from private dependency 'priv_dep' is re-exported + --> $DIR/pub-priv1.rs:177:9 + | +LL | pub use priv_dep::OtherType as Renamed; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: type `OtherType` from private dependency 'priv_dep' in public interface --> $DIR/pub-priv1.rs:29:5 | @@ -49,82 +73,208 @@ LL | pub field: OtherType, error: type `OtherType` from private dependency 'priv_dep' in public interface --> $DIR/pub-priv1.rs:36:5 | +LL | pub OtherType, + | ^^^^^^^^^^^^^ + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:44:21 + | +LL | ActualOtherType(OtherType, PubType), + | ^^^^^^^^^ + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:47:9 + | +LL | field: OtherType, + | ^^^^^^^^^^^^^^^^ + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:54:1 + | +LL | pub type ReexportedPublicGeneric = PublicGenericType; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:56:1 + | +LL | pub type ReexportedPrivateGeneric = PublicGenericType<(), OtherType>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: trait `OtherTrait` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:59:1 + | +LL | pub struct PublicGenericBoundedType(T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:63:5 + | LL | pub fn pub_fn_param(param: OtherType) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: type `OtherType` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:39:5 + --> $DIR/pub-priv1.rs:66:5 | LL | pub fn pub_fn_return() -> OtherType { OtherType } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: trait `OtherTrait` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:46:5 + --> $DIR/pub-priv1.rs:73:5 | LL | type Foo: OtherTrait; | ^^^^^^^^^^^^^^^^^^^^ error: trait `OtherTrait` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:50:1 + --> $DIR/pub-priv1.rs:76:33 + | +LL | fn required_impl_trait() -> impl OtherTrait; + | ^^^^^^^^^^^^^^^ + +error: trait `OtherTrait` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:79:33 + | +LL | fn provided_impl_trait() -> impl OtherTrait { OtherType } + | ^^^^^^^^^^^^^^^ + +error: trait `OtherTrait` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:79:33 + | +LL | fn provided_impl_trait() -> impl OtherTrait { OtherType } + | ^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:83:5 + | +LL | fn required_concrete() -> OtherType; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:86:5 + | +LL | fn provided_concrete() -> OtherType { OtherType } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: trait `OtherTrait` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:90:1 | LL | pub trait WithSuperTrait: OtherTrait {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: type `OtherType` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:59:5 + --> $DIR/pub-priv1.rs:99:5 | LL | type X = OtherType; | ^^^^^^ error: trait `OtherTrait` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:63:1 + --> $DIR/pub-priv1.rs:103:1 | LL | pub fn in_bounds(x: T) { unimplemented!() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: trait `OtherTrait` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:106:1 + | +LL | pub fn private_return_impl_trait() -> impl OtherTrait { OtherType } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: type `OtherType` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:66:1 + --> $DIR/pub-priv1.rs:109:1 + | +LL | pub fn private_return() -> OtherType { OtherType } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:112:1 | LL | pub fn private_in_generic() -> std::num::Saturating { unimplemented!() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: type `OtherType` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:69:1 + --> $DIR/pub-priv1.rs:115:1 | LL | pub static STATIC: OtherType = OtherType; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: type `OtherType` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:72:1 + --> $DIR/pub-priv1.rs:118:1 | LL | pub const CONST: OtherType = OtherType; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: type `OtherType` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:75:1 + --> $DIR/pub-priv1.rs:121:1 | LL | pub type Alias = OtherType; | ^^^^^^^^^^^^^^ +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:124:1 + | +LL | pub type AliasOfAlias = priv_dep::PubPub; + | ^^^^^^^^^^^^^^^^^^^^^ + error: trait `OtherTrait` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:80:1 + --> $DIR/pub-priv1.rs:129:1 | LL | impl OtherTrait for PublicWithPrivateImpl {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: type `OtherType` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:85:1 + --> $DIR/pub-priv1.rs:134:1 | LL | impl PubTraitOnPrivate for OtherType {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: type `OtherType` from private dependency 'priv_dep' in public interface - --> $DIR/pub-priv1.rs:85:1 + --> $DIR/pub-priv1.rs:134:1 | LL | impl PubTraitOnPrivate for OtherType {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 20 previous errors +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:140:1 + | +LL | impl From for PublicWithStdImpl { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:142:5 + | +LL | fn from(val: OtherType) -> Self { Self } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:146:1 + | +LL | impl From for OtherType { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:146:1 + | +LL | impl From for OtherType { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:149:5 + | +LL | fn from(val: PublicWithStdImpl) -> Self { Self } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: type `OtherType` from private dependency 'priv_dep' in public interface + --> $DIR/pub-priv1.rs:149:5 + | +LL | fn from(val: PublicWithStdImpl) -> Self { Self } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 44 previous errors