Skip to content

Commit 1bfd646

Browse files
authored
Rollup merge of rust-lang#144082 - mladedav:dm/pub-priv-tests, r=petrochenkov
tests: cover more `exported_private_dependencies` cases This PR adds tests for all missing cases from rust-lang#71043 and some on top of that. I believe with this, that issue can be closed. Some of the lints can be improved, e.g. `provided_impl_trait` and `impl From<PublicWithStdImpl> for OtherType` lint twice. cc `@epage` in case you want to double check I didn't miss anything.
2 parents 4a81583 + 725523e commit 1bfd646

File tree

3 files changed

+223
-20
lines changed

3 files changed

+223
-20
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: 69 additions & 2 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+
pub 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
@@ -46,9 +73,15 @@ pub trait MyPubTrait {
4673
type Foo: OtherTrait;
4774
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
4875

49-
fn required() -> impl OtherTrait;
76+
fn required_impl_trait() -> impl OtherTrait;
5077

51-
fn provided() -> impl OtherTrait { OtherType }
78+
fn provided_impl_trait() -> impl OtherTrait { OtherType }
79+
80+
fn required_concrete() -> OtherType;
81+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
82+
83+
fn provided_concrete() -> OtherType { OtherType }
84+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
5285
}
5386

5487
pub trait WithSuperTrait: OtherTrait {}
@@ -67,6 +100,12 @@ impl PubLocalTraitWithAssoc for PrivateAssoc {
67100
pub fn in_bounds<T: OtherTrait>(x: T) { unimplemented!() }
68101
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
69102

103+
pub fn private_return_impl_trait() -> impl OtherTrait { OtherType }
104+
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
105+
106+
pub fn private_return() -> OtherType { OtherType }
107+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
108+
70109
pub fn private_in_generic() -> std::num::Saturating<OtherType> { unimplemented!() }
71110
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
72111

@@ -79,6 +118,9 @@ pub const CONST: OtherType = OtherType;
79118
pub type Alias = OtherType;
80119
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
81120

121+
pub type AliasOfAlias = priv_dep::PubPub;
122+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
123+
82124
pub struct PublicWithPrivateImpl;
83125

84126
impl OtherTrait for PublicWithPrivateImpl {}
@@ -90,6 +132,22 @@ impl PubTraitOnPrivate for OtherType {}
90132
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
91133
//~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface
92134

135+
pub struct PublicWithStdImpl;
136+
137+
impl From<OtherType> for PublicWithStdImpl {
138+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
139+
fn from(val: OtherType) -> Self { Self }
140+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
141+
}
142+
143+
impl From<PublicWithStdImpl> for OtherType {
144+
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
145+
//~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface
146+
fn from(val: PublicWithStdImpl) -> Self { Self }
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+
}
150+
93151
pub struct AllowedPrivType {
94152
#[allow(exported_private_dependencies)]
95153
pub allowed: OtherType,
@@ -107,4 +165,13 @@ pub use pm::pm_attr;
107165
pub use priv_dep::E::V1;
108166
//~^ ERROR variant `V1` from private dependency 'priv_dep' is re-exported
109167

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

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

Lines changed: 148 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,59 @@ LL | #![deny(exported_private_dependencies)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: macro `m` from private dependency 'priv_dep' is re-exported
14-
--> $DIR/pub-priv1.rs:98:9
14+
--> $DIR/pub-priv1.rs:156:9
1515
|
1616
LL | pub use priv_dep::m;
1717
| ^^^^^^^^^^^
1818

1919
error: macro `fn_like` from private dependency 'pm' is re-exported
20-
--> $DIR/pub-priv1.rs:100:9
20+
--> $DIR/pub-priv1.rs:158:9
2121
|
2222
LL | pub use pm::fn_like;
2323
| ^^^^^^^^^^^
2424

2525
error: derive macro `PmDerive` from private dependency 'pm' is re-exported
26-
--> $DIR/pub-priv1.rs:102:9
26+
--> $DIR/pub-priv1.rs:160:9
2727
|
2828
LL | pub use pm::PmDerive;
2929
| ^^^^^^^^^^^^
3030

3131
error: attribute macro `pm_attr` from private dependency 'pm' is re-exported
32-
--> $DIR/pub-priv1.rs:104:9
32+
--> $DIR/pub-priv1.rs:162:9
3333
|
3434
LL | pub use pm::pm_attr;
3535
| ^^^^^^^^^^^
3636

3737
error: variant `V1` from private dependency 'priv_dep' is re-exported
38-
--> $DIR/pub-priv1.rs:107:9
38+
--> $DIR/pub-priv1.rs:165:9
3939
|
4040
LL | pub use priv_dep::E::V1;
4141
| ^^^^^^^^^^^^^^^
4242

43+
error: type alias `Unit` from private dependency 'priv_dep' is re-exported
44+
--> $DIR/pub-priv1.rs:168:9
45+
|
46+
LL | pub use priv_dep::Unit;
47+
| ^^^^^^^^^^^^^^
48+
49+
error: type alias `PubPub` from private dependency 'priv_dep' is re-exported
50+
--> $DIR/pub-priv1.rs:170:9
51+
|
52+
LL | pub use priv_dep::PubPub;
53+
| ^^^^^^^^^^^^^^^^
54+
55+
error: type alias `PubPriv` from private dependency 'priv_dep' is re-exported
56+
--> $DIR/pub-priv1.rs:172:9
57+
|
58+
LL | pub use priv_dep::PubPriv;
59+
| ^^^^^^^^^^^^^^^^^
60+
61+
error: struct `Renamed` from private dependency 'priv_dep' is re-exported
62+
--> $DIR/pub-priv1.rs:174:9
63+
|
64+
LL | pub use priv_dep::OtherType as Renamed;
65+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66+
4367
error: type `OtherType` from private dependency 'priv_dep' in public interface
4468
--> $DIR/pub-priv1.rs:29:5
4569
|
@@ -49,82 +73,188 @@ LL | pub field: OtherType,
4973
error: type `OtherType` from private dependency 'priv_dep' in public interface
5074
--> $DIR/pub-priv1.rs:36:5
5175
|
76+
LL | pub OtherType,
77+
| ^^^^^^^^^^^^^
78+
79+
error: type `OtherType` from private dependency 'priv_dep' in public interface
80+
--> $DIR/pub-priv1.rs:44:21
81+
|
82+
LL | ActualOtherType(OtherType, PubType),
83+
| ^^^^^^^^^
84+
85+
error: type `OtherType` from private dependency 'priv_dep' in public interface
86+
--> $DIR/pub-priv1.rs:47:9
87+
|
88+
LL | field: OtherType,
89+
| ^^^^^^^^^^^^^^^^
90+
91+
error: type `OtherType` from private dependency 'priv_dep' in public interface
92+
--> $DIR/pub-priv1.rs:54:1
93+
|
94+
LL | pub type ReexportedPublicGeneric = PublicGenericType<OtherType, ()>;
95+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
96+
97+
error: type `OtherType` from private dependency 'priv_dep' in public interface
98+
--> $DIR/pub-priv1.rs:56:1
99+
|
100+
LL | pub type ReexportedPrivateGeneric = PublicGenericType<(), OtherType>;
101+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102+
103+
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
104+
--> $DIR/pub-priv1.rs:59:1
105+
|
106+
LL | pub struct PublicGenericBoundedType<T: OtherTrait>(T);
107+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
108+
109+
error: type `OtherType` from private dependency 'priv_dep' in public interface
110+
--> $DIR/pub-priv1.rs:63:5
111+
|
52112
LL | pub fn pub_fn_param(param: OtherType) {}
53113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54114

55115
error: type `OtherType` from private dependency 'priv_dep' in public interface
56-
--> $DIR/pub-priv1.rs:39:5
116+
--> $DIR/pub-priv1.rs:66:5
57117
|
58118
LL | pub fn pub_fn_return() -> OtherType { OtherType }
59119
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60120

61121
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
62-
--> $DIR/pub-priv1.rs:46:5
122+
--> $DIR/pub-priv1.rs:73:5
63123
|
64124
LL | type Foo: OtherTrait;
65125
| ^^^^^^^^^^^^^^^^^^^^
66126

127+
error: type `OtherType` from private dependency 'priv_dep' in public interface
128+
--> $DIR/pub-priv1.rs:80:5
129+
|
130+
LL | fn required_concrete() -> OtherType;
131+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
133+
error: type `OtherType` from private dependency 'priv_dep' in public interface
134+
--> $DIR/pub-priv1.rs:83:5
135+
|
136+
LL | fn provided_concrete() -> OtherType { OtherType }
137+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
138+
67139
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
68-
--> $DIR/pub-priv1.rs:54:1
140+
--> $DIR/pub-priv1.rs:87:1
69141
|
70142
LL | pub trait WithSuperTrait: OtherTrait {}
71143
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
72144

73145
error: type `OtherType` from private dependency 'priv_dep' in public interface
74-
--> $DIR/pub-priv1.rs:63:5
146+
--> $DIR/pub-priv1.rs:96:5
75147
|
76148
LL | type X = OtherType;
77149
| ^^^^^^
78150

79151
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
80-
--> $DIR/pub-priv1.rs:67:1
152+
--> $DIR/pub-priv1.rs:100:1
81153
|
82154
LL | pub fn in_bounds<T: OtherTrait>(x: T) { unimplemented!() }
83155
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84156

157+
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
158+
--> $DIR/pub-priv1.rs:103:1
159+
|
160+
LL | pub fn private_return_impl_trait() -> impl OtherTrait { OtherType }
161+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
162+
163+
error: type `OtherType` from private dependency 'priv_dep' in public interface
164+
--> $DIR/pub-priv1.rs:106:1
165+
|
166+
LL | pub fn private_return() -> OtherType { OtherType }
167+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
168+
85169
error: type `OtherType` from private dependency 'priv_dep' in public interface
86-
--> $DIR/pub-priv1.rs:70:1
170+
--> $DIR/pub-priv1.rs:109:1
87171
|
88172
LL | pub fn private_in_generic() -> std::num::Saturating<OtherType> { unimplemented!() }
89173
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
90174

91175
error: type `OtherType` from private dependency 'priv_dep' in public interface
92-
--> $DIR/pub-priv1.rs:73:1
176+
--> $DIR/pub-priv1.rs:112:1
93177
|
94178
LL | pub static STATIC: OtherType = OtherType;
95179
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
96180

97181
error: type `OtherType` from private dependency 'priv_dep' in public interface
98-
--> $DIR/pub-priv1.rs:76:1
182+
--> $DIR/pub-priv1.rs:115:1
99183
|
100184
LL | pub const CONST: OtherType = OtherType;
101185
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
102186

103187
error: type `OtherType` from private dependency 'priv_dep' in public interface
104-
--> $DIR/pub-priv1.rs:79:1
188+
--> $DIR/pub-priv1.rs:118:1
105189
|
106190
LL | pub type Alias = OtherType;
107191
| ^^^^^^^^^^^^^^
108192

193+
error: type `OtherType` from private dependency 'priv_dep' in public interface
194+
--> $DIR/pub-priv1.rs:121:1
195+
|
196+
LL | pub type AliasOfAlias = priv_dep::PubPub;
197+
| ^^^^^^^^^^^^^^^^^^^^^
198+
109199
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface
110-
--> $DIR/pub-priv1.rs:84:1
200+
--> $DIR/pub-priv1.rs:126:1
111201
|
112202
LL | impl OtherTrait for PublicWithPrivateImpl {}
113203
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114204

115205
error: type `OtherType` from private dependency 'priv_dep' in public interface
116-
--> $DIR/pub-priv1.rs:89:1
206+
--> $DIR/pub-priv1.rs:131:1
117207
|
118208
LL | impl PubTraitOnPrivate for OtherType {}
119209
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120210

121211
error: type `OtherType` from private dependency 'priv_dep' in public interface
122-
--> $DIR/pub-priv1.rs:89:1
212+
--> $DIR/pub-priv1.rs:131:1
123213
|
124214
LL | impl PubTraitOnPrivate for OtherType {}
125215
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126216
|
127217
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
128218

129-
error: aborting due to 20 previous errors
219+
error: type `OtherType` from private dependency 'priv_dep' in public interface
220+
--> $DIR/pub-priv1.rs:137:1
221+
|
222+
LL | impl From<OtherType> for PublicWithStdImpl {
223+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
224+
225+
error: type `OtherType` from private dependency 'priv_dep' in public interface
226+
--> $DIR/pub-priv1.rs:139:5
227+
|
228+
LL | fn from(val: OtherType) -> Self { Self }
229+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
230+
231+
error: type `OtherType` from private dependency 'priv_dep' in public interface
232+
--> $DIR/pub-priv1.rs:143:1
233+
|
234+
LL | impl From<PublicWithStdImpl> for OtherType {
235+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
236+
237+
error: type `OtherType` from private dependency 'priv_dep' in public interface
238+
--> $DIR/pub-priv1.rs:143:1
239+
|
240+
LL | impl From<PublicWithStdImpl> for OtherType {
241+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
242+
|
243+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
244+
245+
error: type `OtherType` from private dependency 'priv_dep' in public interface
246+
--> $DIR/pub-priv1.rs:146:5
247+
|
248+
LL | fn from(val: PublicWithStdImpl) -> Self { Self }
249+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
250+
251+
error: type `OtherType` from private dependency 'priv_dep' in public interface
252+
--> $DIR/pub-priv1.rs:146:5
253+
|
254+
LL | fn from(val: PublicWithStdImpl) -> Self { Self }
255+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
256+
|
257+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
258+
259+
error: aborting due to 41 previous errors
130260

0 commit comments

Comments
 (0)