Skip to content

Commit 88acc84

Browse files
Clean up E0026
1 parent 57564c8 commit 88acc84

File tree

1 file changed

+10
-27
lines changed
  • src/librustc_error_codes/error_codes

1 file changed

+10
-27
lines changed
Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,34 @@
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
266
struct Thing {
277
x: u32,
28-
y: u32
8+
y: u32,
299
}
3010
3111
let thing = Thing { x: 0, y: 0 };
3212
3313
match 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
```
4124
struct Thing {
4225
x: u32,
43-
y: u32
26+
y: u32,
4427
}
4528
4629
let thing = Thing { x: 0, y: 0 };
4730
4831
match thing {
49-
Thing { x, y: z } => {}
32+
Thing { x, y: z } => {} // we renamed `y` to `z`
5033
}
5134
```

0 commit comments

Comments
 (0)