]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0027.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0027.md
1 A pattern for a struct fails to specify a sub-pattern for every one of the
2 struct's fields.
3
4 Erroneous code example:
5
6 ```compile_fail,E0027
7 struct Dog {
8     name: String,
9     age: u32,
10 }
11
12 let d = Dog { name: "Rusty".to_string(), age: 8 };
13
14 // This is incorrect.
15 match d {
16     Dog { age: x } => {}
17 }
18 ```
19
20 To fix this error, ensure that each field from the struct's definition is
21 mentioned in the pattern, or use `..` to ignore unwanted fields. Example:
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 ```