File tree 1 file changed +24
-8
lines changed
src/librustc_error_codes/error_codes
1 file changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ Erroneous code example:
4
4
5
5
``` compile_fail,E0446
6
6
#![deny(private_in_public)]
7
+ struct Bar(u32);
7
8
8
- mod Foo {
9
- struct Bar(u32);
10
-
9
+ mod foo {
10
+ use crate::Bar;
11
11
pub fn bar() -> Bar { // error: private type in public interface
12
12
Bar(0)
13
13
}
@@ -16,15 +16,31 @@ mod Foo {
16
16
fn main() {}
17
17
```
18
18
19
- To solve this error, please ensure that the type is also public. The type
20
- can be made inaccessible if necessary by placing it into a private inner
21
- module, but it still has to be marked with ` pub ` .
19
+ There are two ways to solve this error. The first is to make the public type
20
+ signature only public to a module that also has access to the private type.
21
+ This is done by using pub(crate) or pub(in crate::my_mod::etc)
22
22
Example:
23
23
24
24
```
25
- mod Foo {
26
- pub struct Bar(u32); // we set the Bar type public
25
+ struct Bar(u32);
26
+
27
+ mod foo {
28
+ use crate::Bar;
29
+ pub(crate) fn bar() -> Bar { // only public to crate root
30
+ Bar(0)
31
+ }
32
+ }
27
33
34
+ fn main() {}
35
+ ```
36
+
37
+ The other way to solve this error is to make the private type public.
38
+ Example:
39
+
40
+ ```
41
+ pub struct Bar(u32); // we set the Bar type public
42
+ mod foo {
43
+ use crate::Bar;
28
44
pub fn bar() -> Bar { // ok!
29
45
Bar(0)
30
46
}
You can’t perform that action at this time.
0 commit comments