File tree Expand file tree Collapse file tree 1 file changed +10
-27
lines changed
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 1 file changed +10
-27
lines changed Original file line number Diff line number Diff line change 1- This error indicates that a struct pattern attempted to extract a non-existent
2- field from a struct. Struct fields are identified by the name used before the
3- colon ` : ` so struct patterns should resemble the declaration of the struct type
4- being matched.
1+ A struct pattern attempted to extract a non-existent field from a struct.
52
6- ```
7- // Correct matching.
8- struct Thing {
9- x: u32,
10- y: u32
11- }
12-
13- let thing = Thing { x: 1, y: 2 };
14-
15- match thing {
16- Thing { x: xfield, y: yfield } => {}
17- }
18- ```
19-
20- If you are using shorthand field patterns but want to refer to the struct field
21- by a different name, you should rename it explicitly.
22-
23- Change this:
3+ Erroneous code example:
244
255``` compile_fail,E0026
266struct Thing {
277 x: u32,
28- y: u32
8+ y: u32,
299}
3010
3111let thing = Thing { x: 0, y: 0 };
3212
3313match thing {
34- Thing { x, z } => {}
14+ Thing { x, z } => {} // error: `Thing::z` field doesn't exist
3515}
3616```
3717
38- To this:
18+ If you are using shorthand field patterns but want to refer to the struct field
19+ by a different name, you should rename it explicitly. Struct fields are
20+ identified by the name used before the colon ` : ` so struct patterns should
21+ resemble the declaration of the struct type being matched.
3922
4023```
4124struct Thing {
4225 x: u32,
43- y: u32
26+ y: u32,
4427}
4528
4629let thing = Thing { x: 0, y: 0 };
4730
4831match thing {
49- Thing { x, y: z } => {}
32+ Thing { x, y: z } => {} // we renamed `y` to `z`
5033}
5134```
You can’t perform that action at this time.
0 commit comments