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.
5
2
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:
24
4
25
5
``` compile_fail,E0026
26
6
struct Thing {
27
7
x: u32,
28
- y: u32
8
+ y: u32,
29
9
}
30
10
31
11
let thing = Thing { x: 0, y: 0 };
32
12
33
13
match thing {
34
- Thing { x, z } => {}
14
+ Thing { x, z } => {} // error: `Thing::z` field doesn't exist
35
15
}
36
16
```
37
17
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.
39
22
40
23
```
41
24
struct Thing {
42
25
x: u32,
43
- y: u32
26
+ y: u32,
44
27
}
45
28
46
29
let thing = Thing { x: 0, y: 0 };
47
30
48
31
match thing {
49
- Thing { x, y: z } => {}
32
+ Thing { x, y: z } => {} // we renamed `y` to `z`
50
33
}
51
34
```
You can’t perform that action at this time.
0 commit comments