]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0062.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0062.md
1 A struct's or struct-like enum variant's field was specified more than once.
2
3 Erroneous code example:
4
5 ```compile_fail,E0062
6 struct Foo {
7     x: i32,
8 }
9
10 fn main() {
11     let x = Foo {
12                 x: 0,
13                 x: 0, // error: field `x` specified more than once
14             };
15 }
16 ```
17
18 This error indicates that during an attempt to build a struct or struct-like
19 enum variant, one of the fields was specified more than once. Each field should
20 be specified exactly one time. Example:
21
22 ```
23 struct Foo {
24     x: i32,
25 }
26
27 fn main() {
28     let x = Foo { x: 0 }; // ok!
29 }
30 ```