]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
1 | A private item was used outside its scope. |
2 | ||
3 | Erroneous code example: | |
4 | ||
5 | ```compile_fail,E0603 | |
923072b8 | 6 | mod foo { |
60c5eb7d XL |
7 | const PRIVATE: u32 = 0x_a_bad_1dea_u32; // This const is private, so we |
8 | // can't use it outside of the | |
923072b8 | 9 | // `foo` module. |
60c5eb7d XL |
10 | } |
11 | ||
923072b8 | 12 | println!("const value: {}", foo::PRIVATE); // error: constant `PRIVATE` |
60c5eb7d XL |
13 | // is private |
14 | ``` | |
15 | ||
16 | In order to fix this error, you need to make the item public by using the `pub` | |
17 | keyword. Example: | |
18 | ||
19 | ``` | |
923072b8 | 20 | mod foo { |
60c5eb7d XL |
21 | pub const PRIVATE: u32 = 0x_a_bad_1dea_u32; // We set it public by using the |
22 | // `pub` keyword. | |
23 | } | |
24 | ||
923072b8 | 25 | println!("const value: {}", foo::PRIVATE); // ok! |
60c5eb7d | 26 | ``` |