File tree Expand file tree Collapse file tree 1 file changed +24
-8
lines changed
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 1 file changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ Erroneous code example:
44
55``` compile_fail,E0446
66#![deny(private_in_public)]
7+ struct Bar(u32);
78
8- mod Foo {
9- struct Bar(u32);
10-
9+ mod foo {
10+ use crate::Bar;
1111 pub fn bar() -> Bar { // error: private type in public interface
1212 Bar(0)
1313 }
@@ -16,15 +16,31 @@ mod Foo {
1616fn main() {}
1717```
1818
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)
2222Example:
2323
2424```
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+ }
2733
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;
2844 pub fn bar() -> Bar { // ok!
2945 Bar(0)
3046 }
You can’t perform that action at this time.
0 commit comments