This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +27
-27
lines changed
compiler/rustc_error_codes/src/error_codes Expand file tree Collapse file tree 5 files changed +27
-27
lines changed Original file line number Diff line number Diff line change @@ -3,35 +3,35 @@ A struct constructor with private fields was invoked.
33Erroneous code example:
44
55``` compile_fail,E0451
6- mod Bar {
6+ mod bar {
77 pub struct Foo {
88 pub a: isize,
99 b: isize,
1010 }
1111}
1212
13- let f = Bar ::Foo{ a: 0, b: 0 }; // error: field `b` of struct `Bar ::Foo`
13+ let f = bar ::Foo{ a: 0, b: 0 }; // error: field `b` of struct `bar ::Foo`
1414 // is private
1515```
1616
1717To fix this error, please ensure that all the fields of the struct are public,
1818or implement a function for easy instantiation. Examples:
1919
2020```
21- mod Bar {
21+ mod bar {
2222 pub struct Foo {
2323 pub a: isize,
2424 pub b: isize, // we set `b` field public
2525 }
2626}
2727
28- let f = Bar ::Foo{ a: 0, b: 0 }; // ok!
28+ let f = bar ::Foo{ a: 0, b: 0 }; // ok!
2929```
3030
3131Or:
3232
3333```
34- mod Bar {
34+ mod bar {
3535 pub struct Foo {
3636 pub a: isize,
3737 b: isize, // still private
@@ -44,5 +44,5 @@ mod Bar {
4444 }
4545}
4646
47- let f = Bar ::Foo::new(); // ok!
47+ let f = bar ::Foo::new(); // ok!
4848```
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ expected.
44Erroneous code example:
55
66``` compile_fail,E0574
7- mod Mordor {}
7+ mod mordor {}
88
9- let sauron = Mordor { x: () }; // error!
9+ let sauron = mordor { x: () }; // error!
1010
1111enum Jak {
1212 Daxter { i: isize },
@@ -19,17 +19,17 @@ match eco {
1919```
2020
2121In all these errors, a type was expected. For example, in the first error,
22- we tried to instantiate the ` Mordor ` module, which is impossible. If you want
22+ we tried to instantiate the ` mordor ` module, which is impossible. If you want
2323to instantiate a type inside a module, you can do it as follow:
2424
2525```
26- mod Mordor {
26+ mod mordor {
2727 pub struct TheRing {
2828 pub x: usize,
2929 }
3030}
3131
32- let sauron = Mordor ::TheRing { x: 1 }; // ok!
32+ let sauron = mordor ::TheRing { x: 1 }; // ok!
3333```
3434
3535In the second error, we tried to bind the ` Jak ` enum directly, which is not
Original file line number Diff line number Diff line change @@ -11,13 +11,13 @@ fn main() {}
1111```
1212
1313` Sea ` is not a module, therefore it is invalid to use it in a visibility path.
14- To fix this error we need to ensure ` Sea ` is a module.
14+ To fix this error we need to ensure ` sea ` is a module.
1515
1616Please note that the visibility scope can only be applied on ancestors!
1717
1818``` edition2018
19- pub mod Sea {
20- pub (in crate::Sea ) struct Shark; // ok!
19+ pub mod sea {
20+ pub (in crate::sea ) struct Shark; // ok!
2121}
2222
2323fn main() {}
Original file line number Diff line number Diff line change @@ -3,24 +3,24 @@ A private item was used outside its scope.
33Erroneous code example:
44
55``` compile_fail,E0603
6- mod SomeModule {
6+ mod foo {
77 const PRIVATE: u32 = 0x_a_bad_1dea_u32; // This const is private, so we
88 // can't use it outside of the
9- // `SomeModule ` module.
9+ // `foo ` module.
1010}
1111
12- println!("const value: {}", SomeModule ::PRIVATE); // error: constant `PRIVATE`
12+ println!("const value: {}", foo ::PRIVATE); // error: constant `PRIVATE`
1313 // is private
1414```
1515
1616In order to fix this error, you need to make the item public by using the ` pub `
1717keyword. Example:
1818
1919```
20- mod SomeModule {
20+ mod foo {
2121 pub const PRIVATE: u32 = 0x_a_bad_1dea_u32; // We set it public by using the
2222 // `pub` keyword.
2323}
2424
25- println!("const value: {}", SomeModule ::PRIVATE); // ok!
25+ println!("const value: {}", foo ::PRIVATE); // ok!
2626```
Original file line number Diff line number Diff line change 44Erroneous code example:
55
66``` compile_fail,E0742,edition2018
7- pub mod Sea {}
7+ pub mod sea {}
88
9- pub (in crate::Sea ) struct Shark; // error!
9+ pub (in crate::sea ) struct Shark; // error!
1010
1111fn main() {}
1212```
1313
14- To fix this error, we need to move the ` Shark ` struct inside the ` Sea ` module:
14+ To fix this error, we need to move the ` Shark ` struct inside the ` sea ` module:
1515
1616``` edition2018
17- pub mod Sea {
18- pub (in crate::Sea ) struct Shark; // ok!
17+ pub mod sea {
18+ pub (in crate::sea ) struct Shark; // ok!
1919}
2020
2121fn main() {}
@@ -25,9 +25,9 @@ Of course, you can do it as long as the module you're referring to is an
2525ancestor:
2626
2727``` edition2018
28- pub mod Earth {
29- pub mod Sea {
30- pub (in crate::Earth ) struct Shark; // ok!
28+ pub mod earth {
29+ pub mod sea {
30+ pub (in crate::earth ) struct Shark; // ok!
3131 }
3232}
3333
You can’t perform that action at this time.
0 commit comments