Skip to content

Commit 5d8dc90

Browse files
Improve E0025 error explanation
1 parent 612221f commit 5d8dc90

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,39 @@ the enum.
7373
"##,
7474

7575
E0025: r##"
76-
Each field of a struct can only be bound once in a pattern. Each occurrence of a
77-
field name binds the value of that field, so to fix this error you will have to
78-
remove or alter the duplicate uses of the field name. Perhaps you misspelt
79-
another field name?
76+
Each field of a struct can only be bound once in a pattern. Erroneous code
77+
example:
78+
79+
```
80+
struct Foo {
81+
a: u8,
82+
b: u8,
83+
}
84+
85+
fn main(){
86+
let x = Foo { a:1, b:2 };
87+
88+
let Foo { a: x, a: y } = x;
89+
// error: field `a` bound multiple times in the pattern
90+
}
91+
```
92+
93+
Each occurrence of a field name binds the value of that field, so to fix this
94+
error you will have to remove or alter the duplicate uses of the field name.
95+
Perhaps you misspelled another field name? Example:
96+
97+
```
98+
struct Foo {
99+
a: u8,
100+
b: u8,
101+
}
102+
103+
fn main(){
104+
let x = Foo { a:1, b:2 };
105+
106+
let Foo { a: x, b: y } = x; // ok!
107+
}
108+
```
80109
"##,
81110

82111
E0026: r##"

0 commit comments

Comments
 (0)