Skip to content

Commit 190dc87

Browse files
Add new UI test for private types in public APIs
1 parent 20ff89f commit 190dc87

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// This ui test checks that private types present in public APIs get
2+
// a warning.
3+
4+
#![crate_type = "lib"]
5+
#![deny(private_in_public)]
6+
7+
mod my_type {
8+
pub struct Field;
9+
pub struct MyType {
10+
pub field: Field,
11+
}
12+
13+
impl MyType {
14+
pub fn builder() -> MyTypeBuilder {
15+
//~^ ERROR
16+
//~| WARN
17+
MyTypeBuilder { field: Field }
18+
}
19+
20+
pub fn with_builder(_: MyTypeBuilder) {}
21+
//~^ ERROR
22+
//~| WARN
23+
}
24+
25+
pub struct MyTypeBuilder {
26+
field: Field,
27+
}
28+
29+
impl MyTypeBuilder {
30+
pub fn field(mut self, val: Field) -> Self {
31+
self.field = val;
32+
33+
self
34+
}
35+
36+
pub fn build(self) -> MyType {
37+
MyType { field: self.field }
38+
}
39+
}
40+
}
41+
42+
pub use my_type::{MyType, Field};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: public but not reexported type `MyTypeBuilder` in public interface (error E0446)
2+
--> $DIR/local-public-in-public-api.rs:14:9
3+
|
4+
LL | pub fn builder() -> MyTypeBuilder {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
9+
note: the lint level is defined here
10+
--> $DIR/local-public-in-public-api.rs:5:9
11+
|
12+
LL | #![deny(private_in_public)]
13+
| ^^^^^^^^^^^^^^^^^
14+
15+
error: public but not reexported type `MyTypeBuilder` in public interface (error E0446)
16+
--> $DIR/local-public-in-public-api.rs:20:9
17+
|
18+
LL | pub fn with_builder(_: MyTypeBuilder) {}
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
|
21+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
22+
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
23+
24+
error: aborting due to 2 previous errors
25+

0 commit comments

Comments
 (0)