File tree 5 files changed +27
-27
lines changed
compiler/rustc_error_codes/src/error_codes
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.
3
3
Erroneous code example:
4
4
5
5
``` compile_fail,E0451
6
- mod Bar {
6
+ mod bar {
7
7
pub struct Foo {
8
8
pub a: isize,
9
9
b: isize,
10
10
}
11
11
}
12
12
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`
14
14
// is private
15
15
```
16
16
17
17
To fix this error, please ensure that all the fields of the struct are public,
18
18
or implement a function for easy instantiation. Examples:
19
19
20
20
```
21
- mod Bar {
21
+ mod bar {
22
22
pub struct Foo {
23
23
pub a: isize,
24
24
pub b: isize, // we set `b` field public
25
25
}
26
26
}
27
27
28
- let f = Bar ::Foo{ a: 0, b: 0 }; // ok!
28
+ let f = bar ::Foo{ a: 0, b: 0 }; // ok!
29
29
```
30
30
31
31
Or:
32
32
33
33
```
34
- mod Bar {
34
+ mod bar {
35
35
pub struct Foo {
36
36
pub a: isize,
37
37
b: isize, // still private
@@ -44,5 +44,5 @@ mod Bar {
44
44
}
45
45
}
46
46
47
- let f = Bar ::Foo::new(); // ok!
47
+ let f = bar ::Foo::new(); // ok!
48
48
```
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ expected.
4
4
Erroneous code example:
5
5
6
6
``` compile_fail,E0574
7
- mod Mordor {}
7
+ mod mordor {}
8
8
9
- let sauron = Mordor { x: () }; // error!
9
+ let sauron = mordor { x: () }; // error!
10
10
11
11
enum Jak {
12
12
Daxter { i: isize },
@@ -19,17 +19,17 @@ match eco {
19
19
```
20
20
21
21
In 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
23
23
to instantiate a type inside a module, you can do it as follow:
24
24
25
25
```
26
- mod Mordor {
26
+ mod mordor {
27
27
pub struct TheRing {
28
28
pub x: usize,
29
29
}
30
30
}
31
31
32
- let sauron = Mordor ::TheRing { x: 1 }; // ok!
32
+ let sauron = mordor ::TheRing { x: 1 }; // ok!
33
33
```
34
34
35
35
In 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() {}
11
11
```
12
12
13
13
` 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.
15
15
16
16
Please note that the visibility scope can only be applied on ancestors!
17
17
18
18
``` 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!
21
21
}
22
22
23
23
fn main() {}
Original file line number Diff line number Diff line change @@ -3,24 +3,24 @@ A private item was used outside its scope.
3
3
Erroneous code example:
4
4
5
5
``` compile_fail,E0603
6
- mod SomeModule {
6
+ mod foo {
7
7
const PRIVATE: u32 = 0x_a_bad_1dea_u32; // This const is private, so we
8
8
// can't use it outside of the
9
- // `SomeModule ` module.
9
+ // `foo ` module.
10
10
}
11
11
12
- println!("const value: {}", SomeModule ::PRIVATE); // error: constant `PRIVATE`
12
+ println!("const value: {}", foo ::PRIVATE); // error: constant `PRIVATE`
13
13
// is private
14
14
```
15
15
16
16
In order to fix this error, you need to make the item public by using the ` pub `
17
17
keyword. Example:
18
18
19
19
```
20
- mod SomeModule {
20
+ mod foo {
21
21
pub const PRIVATE: u32 = 0x_a_bad_1dea_u32; // We set it public by using the
22
22
// `pub` keyword.
23
23
}
24
24
25
- println!("const value: {}", SomeModule ::PRIVATE); // ok!
25
+ println!("const value: {}", foo ::PRIVATE); // ok!
26
26
```
Original file line number Diff line number Diff line change 4
4
Erroneous code example:
5
5
6
6
``` compile_fail,E0742,edition2018
7
- pub mod Sea {}
7
+ pub mod sea {}
8
8
9
- pub (in crate::Sea ) struct Shark; // error!
9
+ pub (in crate::sea ) struct Shark; // error!
10
10
11
11
fn main() {}
12
12
```
13
13
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:
15
15
16
16
``` 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!
19
19
}
20
20
21
21
fn main() {}
@@ -25,9 +25,9 @@ Of course, you can do it as long as the module you're referring to is an
25
25
ancestor:
26
26
27
27
``` 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!
31
31
}
32
32
}
33
33
You can’t perform that action at this time.
0 commit comments