Skip to content

Commit 3936e12

Browse files
committed
tests: cover more exported_private_dependencies cases
1 parent e78d086 commit 3936e12

File tree

3 files changed

+159
-16
lines changed

3 files changed

+159
-16
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ macro_rules! m {
1010
pub enum E {
1111
V1
1212
}
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: 55 additions & 0 deletions
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+
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
@@ -82,6 +109,9 @@ pub const CONST: OtherType = OtherType;
82109
pub type Alias = OtherType;
83110
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
84111

112+
pub type AliasOfAlias = priv_dep::PubPub;
113+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
114+
85115
pub struct PublicWithPrivateImpl;
86116

87117
impl OtherTrait for PublicWithPrivateImpl {}
@@ -93,6 +123,22 @@ impl PubTraitOnPrivate for OtherType {}
93123
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
94124
//~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface
95125

126+
pub struct PublicWithStdImpl;
127+
128+
impl From<OtherType> for PublicWithStdImpl {
129+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
130+
fn from(val: OtherType) -> Self { Self }
131+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
132+
}
133+
134+
impl From<PublicWithStdImpl> for OtherType {
135+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
136+
//~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface
137+
fn from(val: PublicWithStdImpl) -> Self { Self }
138+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
139+
//~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface
140+
}
141+
96142
pub struct AllowedPrivType {
97143
#[allow(exported_private_dependencies)]
98144
pub allowed: OtherType,
@@ -110,4 +156,13 @@ pub use pm::pm_attr;
110156
// FIXME: This should trigger.
111157
pub use priv_dep::E::V1;
112158

159+
pub use priv_dep::Unit;
160+
//~^ ERROR type alias `Unit` from private dependency 'priv_dep' is re-exported
161+
pub use priv_dep::PubPub;
162+
//~^ ERROR type alias `PubPub` from private dependency 'priv_dep' is re-exported
163+
pub use priv_dep::PubPriv;
164+
//~^ ERROR type alias `PubPriv` from private dependency 'priv_dep' is re-exported
165+
pub use priv_dep::OtherType as Renamed;
166+
//~^ ERROR struct `Renamed` from private dependency 'priv_dep' is re-exported
167+
113168
fn main() {}

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

Lines changed: 98 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,102 +13,184 @@ LL | #![deny(exported_private_dependencies)]
1313
error: type `OtherType` from private dependency 'priv_dep' in public interface
1414
--> $DIR/pub-priv1.rs:36:5
1515
|
16+
LL | pub OtherType,
17+
| ^^^^^^^^^^^^^
18+
19+
error: type `OtherType` from private dependency 'priv_dep' in public interface
20+
--> $DIR/pub-priv1.rs:44:21
21+
|
22+
LL | ActualOtherType(OtherType, PubType),
23+
| ^^^^^^^^^
24+
25+
error: type `OtherType` from private dependency 'priv_dep' in public interface
26+
--> $DIR/pub-priv1.rs:47:9
27+
|
28+
LL | field: OtherType,
29+
| ^^^^^^^^^^^^^^^^
30+
31+
error: type `OtherType` from private dependency 'priv_dep' in public interface
32+
--> $DIR/pub-priv1.rs:54:1
33+
|
34+
LL | pub type ReexportedPublicGeneric = PublicGenericType<OtherType, ()>;
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
37+
error: type `OtherType` from private dependency 'priv_dep' in public interface
38+
--> $DIR/pub-priv1.rs:56:1
39+
|
40+
LL | pub type ReexportedPrivateGeneric = PublicGenericType<(), OtherType>;
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
43+
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
44+
--> $DIR/pub-priv1.rs:59:1
45+
|
46+
LL | pub struct PublicGenericBoundedType<T: OtherTrait>(T);
47+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48+
49+
error: type `OtherType` from private dependency 'priv_dep' in public interface
50+
--> $DIR/pub-priv1.rs:63:5
51+
|
1652
LL | pub fn pub_fn_param(param: OtherType) {}
1753
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1854

1955
error: type `OtherType` from private dependency 'priv_dep' in public interface
20-
--> $DIR/pub-priv1.rs:39:5
56+
--> $DIR/pub-priv1.rs:66:5
2157
|
2258
LL | pub fn pub_fn_return() -> OtherType { OtherType }
2359
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2460

2561
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
26-
--> $DIR/pub-priv1.rs:46:5
62+
--> $DIR/pub-priv1.rs:73:5
2763
|
2864
LL | type Foo: OtherTrait;
2965
| ^^^^^^^^^^^^^^^^^^^^
3066

3167
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
32-
--> $DIR/pub-priv1.rs:49:22
68+
--> $DIR/pub-priv1.rs:76:22
3369
|
3470
LL | fn required() -> impl OtherTrait;
3571
| ^^^^^^^^^^^^^^^
3672

3773
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
38-
--> $DIR/pub-priv1.rs:52:22
74+
--> $DIR/pub-priv1.rs:79:22
3975
|
4076
LL | fn provided() -> impl OtherTrait { OtherType }
4177
| ^^^^^^^^^^^^^^^
4278

4379
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
44-
--> $DIR/pub-priv1.rs:52:22
80+
--> $DIR/pub-priv1.rs:79:22
4581
|
4682
LL | fn provided() -> impl OtherTrait { OtherType }
4783
| ^^^^^^^^^^^^^^^
4884
|
4985
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5086

5187
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
52-
--> $DIR/pub-priv1.rs:57:1
88+
--> $DIR/pub-priv1.rs:84:1
5389
|
5490
LL | pub trait WithSuperTrait: OtherTrait {}
5591
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5692

5793
error: type `OtherType` from private dependency 'priv_dep' in public interface
58-
--> $DIR/pub-priv1.rs:66:5
94+
--> $DIR/pub-priv1.rs:93:5
5995
|
6096
LL | type X = OtherType;
6197
| ^^^^^^
6298

6399
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
64-
--> $DIR/pub-priv1.rs:70:1
100+
--> $DIR/pub-priv1.rs:97:1
65101
|
66102
LL | pub fn in_bounds<T: OtherTrait>(x: T) { unimplemented!() }
67103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68104

69105
error: type `OtherType` from private dependency 'priv_dep' in public interface
70-
--> $DIR/pub-priv1.rs:73:1
106+
--> $DIR/pub-priv1.rs:100:1
71107
|
72108
LL | pub fn private_in_generic() -> std::num::Saturating<OtherType> { unimplemented!() }
73109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74110

75111
error: type `OtherType` from private dependency 'priv_dep' in public interface
76-
--> $DIR/pub-priv1.rs:76:1
112+
--> $DIR/pub-priv1.rs:103:1
77113
|
78114
LL | pub static STATIC: OtherType = OtherType;
79115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80116

81117
error: type `OtherType` from private dependency 'priv_dep' in public interface
82-
--> $DIR/pub-priv1.rs:79:1
118+
--> $DIR/pub-priv1.rs:106:1
83119
|
84120
LL | pub const CONST: OtherType = OtherType;
85121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
86122

87123
error: type `OtherType` from private dependency 'priv_dep' in public interface
88-
--> $DIR/pub-priv1.rs:82:1
124+
--> $DIR/pub-priv1.rs:109:1
89125
|
90126
LL | pub type Alias = OtherType;
91127
| ^^^^^^^^^^^^^^
92128

129+
error: type `OtherType` from private dependency 'priv_dep' in public interface
130+
--> $DIR/pub-priv1.rs:112:1
131+
|
132+
LL | pub type AliasOfAlias = priv_dep::PubPub;
133+
| ^^^^^^^^^^^^^^^^^^^^^
134+
93135
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
94-
--> $DIR/pub-priv1.rs:87:1
136+
--> $DIR/pub-priv1.rs:117:1
95137
|
96138
LL | impl OtherTrait for PublicWithPrivateImpl {}
97139
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98140

99141
error: type `OtherType` from private dependency 'priv_dep' in public interface
100-
--> $DIR/pub-priv1.rs:92:1
142+
--> $DIR/pub-priv1.rs:122:1
101143
|
102144
LL | impl PubTraitOnPrivate for OtherType {}
103145
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104146

105147
error: type `OtherType` from private dependency 'priv_dep' in public interface
106-
--> $DIR/pub-priv1.rs:92:1
148+
--> $DIR/pub-priv1.rs:122:1
107149
|
108150
LL | impl PubTraitOnPrivate for OtherType {}
109151
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110152
|
111153
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
112154

113-
error: aborting due to 17 previous errors
155+
error: type `OtherType` from private dependency 'priv_dep' in public interface
156+
--> $DIR/pub-priv1.rs:128:1
157+
|
158+
LL | impl From<OtherType> for PublicWithStdImpl {
159+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
160+
161+
error: type `OtherType` from private dependency 'priv_dep' in public interface
162+
--> $DIR/pub-priv1.rs:130:5
163+
|
164+
LL | fn from(val: OtherType) -> Self { Self }
165+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
166+
167+
error: type `OtherType` from private dependency 'priv_dep' in public interface
168+
--> $DIR/pub-priv1.rs:134:1
169+
|
170+
LL | impl From<PublicWithStdImpl> for OtherType {
171+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
172+
173+
error: type `OtherType` from private dependency 'priv_dep' in public interface
174+
--> $DIR/pub-priv1.rs:134:1
175+
|
176+
LL | impl From<PublicWithStdImpl> for OtherType {
177+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
178+
|
179+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
180+
181+
error: type `OtherType` from private dependency 'priv_dep' in public interface
182+
--> $DIR/pub-priv1.rs:137:5
183+
|
184+
LL | fn from(val: PublicWithStdImpl) -> Self { Self }
185+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
186+
187+
error: type `OtherType` from private dependency 'priv_dep' in public interface
188+
--> $DIR/pub-priv1.rs:137:5
189+
|
190+
LL | fn from(val: PublicWithStdImpl) -> Self { Self }
191+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
192+
|
193+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
194+
195+
error: aborting due to 30 previous errors
114196

0 commit comments

Comments
 (0)