Skip to content

Commit 2390abe

Browse files
committed
tests: cover more exported_private_dependencies cases
1 parent bf5e6cc commit 2390abe

File tree

3 files changed

+250
-19
lines changed

3 files changed

+250
-19
lines changed

tests/ui/privacy/pub-priv-dep/auxiliary/priv_dep.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub struct OtherType;
22
pub trait OtherTrait {}
3+
impl OtherTrait for OtherType {}
34

45
#[macro_export]
56
macro_rules! m {
@@ -9,3 +10,9 @@ macro_rules! m {
910
pub enum E {
1011
V1
1112
}
13+
14+
struct PrivType;
15+
16+
pub type Unit = ();
17+
pub type PubPub = OtherType;
18+
pub type PubPriv = PrivType;

tests/ui/privacy/pub-priv-dep/pub-priv1.rs

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,33 @@ pub struct PublicType {
3232
pub other_field: PubType, // Type from public dependency - this is fine
3333
}
3434

35+
pub struct PublicTuple(
36+
pub OtherType,
37+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface [exported_private_dependencies]
38+
OtherType,
39+
PubType,
40+
);
41+
42+
pub enum PublicEnum {
43+
OtherType,
44+
ActualOtherType(OtherType, PubType),
45+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface [exported_private_dependencies]
46+
ActualOtherTypeStruct {
47+
field: OtherType,
48+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface [exported_private_dependencies]
49+
pub other_field: PubType,
50+
},
51+
}
52+
53+
pub struct PublicGenericType<T, U>(pub T, U);
54+
pub type ReexportedPublicGeneric = PublicGenericType<OtherType, ()>;
55+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
56+
pub type ReexportedPrivateGeneric = PublicGenericType<(), OtherType>;
57+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
58+
59+
pub struct PublicGenericBoundedType<T: OtherTrait>(T);
60+
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
61+
3562
impl PublicType {
3663
pub fn pub_fn_param(param: OtherType) {}
3764
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
@@ -44,8 +71,21 @@ impl PublicType {
4471

4572
pub trait MyPubTrait {
4673
type Foo: OtherTrait;
74+
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
75+
76+
fn required_impl_trait() -> impl OtherTrait;
77+
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
78+
79+
fn provided_impl_trait() -> impl OtherTrait { OtherType }
80+
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
81+
//~| ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
82+
83+
fn required_concrete() -> OtherType;
84+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
85+
86+
fn provided_concrete() -> OtherType { OtherType }
87+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
4788
}
48-
//~^^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
4989

5090
pub trait WithSuperTrait: OtherTrait {}
5191
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
@@ -63,6 +103,12 @@ impl PubLocalTraitWithAssoc for PrivateAssoc {
63103
pub fn in_bounds<T: OtherTrait>(x: T) { unimplemented!() }
64104
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
65105

106+
pub fn private_return_impl_trait() -> impl OtherTrait { OtherType }
107+
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
108+
109+
pub fn private_return() -> OtherType { OtherType }
110+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
111+
66112
pub fn private_in_generic() -> std::num::Saturating<OtherType> { unimplemented!() }
67113
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
68114

@@ -75,6 +121,9 @@ pub const CONST: OtherType = OtherType;
75121
pub type Alias = OtherType;
76122
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
77123

124+
pub type AliasOfAlias = priv_dep::PubPub;
125+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
126+
78127
pub struct PublicWithPrivateImpl;
79128

80129
impl OtherTrait for PublicWithPrivateImpl {}
@@ -86,6 +135,22 @@ impl PubTraitOnPrivate for OtherType {}
86135
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
87136
//~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface
88137

138+
pub struct PublicWithStdImpl;
139+
140+
impl From<OtherType> for PublicWithStdImpl {
141+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
142+
fn from(val: OtherType) -> Self { Self }
143+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
144+
}
145+
146+
impl From<PublicWithStdImpl> for OtherType {
147+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
148+
//~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface
149+
fn from(val: PublicWithStdImpl) -> Self { Self }
150+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
151+
//~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface
152+
}
153+
89154
pub struct AllowedPrivType {
90155
#[allow(exported_private_dependencies)]
91156
pub allowed: OtherType,
@@ -103,4 +168,13 @@ pub use pm::pm_attr;
103168
pub use priv_dep::E::V1;
104169
//~^ ERROR variant `V1` from private dependency 'priv_dep' is re-exported
105170

171+
pub use priv_dep::Unit;
172+
//~^ ERROR type alias `Unit` from private dependency 'priv_dep' is re-exported
173+
pub use priv_dep::PubPub;
174+
//~^ ERROR type alias `PubPub` from private dependency 'priv_dep' is re-exported
175+
pub use priv_dep::PubPriv;
176+
//~^ ERROR type alias `PubPriv` from private dependency 'priv_dep' is re-exported
177+
pub use priv_dep::OtherType as Renamed;
178+
//~^ ERROR struct `Renamed` from private dependency 'priv_dep' is re-exported
179+
106180
fn main() {}

0 commit comments

Comments
 (0)