]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0027.md
ab2a20fe9e56d00fb9472b30cbc542a604aeaa71
[rust.git] / src / librustc_error_codes / error_codes / E0027.md
1 This error indicates that a pattern for a struct fails to specify a sub-pattern
2 for every one of the struct's fields. Ensure that each field from the struct's
3 definition is mentioned in the pattern, or use `..` to ignore unwanted fields.
4
5 For example:
6
7 ```compile_fail,E0027
8 struct Dog {
9     name: String,
10     age: u32,
11 }
12
13 let d = Dog { name: "Rusty".to_string(), age: 8 };
14
15 // This is incorrect.
16 match d {
17     Dog { age: x } => {}
18 }
19 ```
20
21 This is correct (explicit):
22
23 ```
24 struct Dog {
25     name: String,
26     age: u32,
27 }
28
29 let d = Dog { name: "Rusty".to_string(), age: 8 };
30
31 match d {
32     Dog { name: ref n, age: x } => {}
33 }
34
35 // This is also correct (ignore unused fields).
36 match d {
37     Dog { age: x, .. } => {}
38 }
39 ```