]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0025.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0025.md
1 Each field of a struct can only be bound once in a pattern.
2
3 Erroneous code example:
4
5 ```compile_fail,E0025
6 struct Foo {
7     a: u8,
8     b: u8,
9 }
10
11 fn main(){
12     let x = Foo { a:1, b:2 };
13
14     let Foo { a: x, a: y } = x;
15     // error: field `a` bound multiple times in the pattern
16 }
17 ```
18
19 Each occurrence of a field name binds the value of that field, so to fix this
20 error you will have to remove or alter the duplicate uses of the field name.
21 Perhaps you misspelled another field name? Example:
22
23 ```
24 struct Foo {
25     a: u8,
26     b: u8,
27 }
28
29 fn main(){
30     let x = Foo { a:1, b:2 };
31
32     let Foo { a: x, b: y } = x; // ok!
33 }
34 ```