Skip to content

Commit 9e51cee

Browse files
Improve E0062 error explanation
1 parent dddc4ca commit 9e51cee

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,32 @@ variadic functions (except for its C-FFI).
640640

641641
E0062: r##"
642642
This error indicates that during an attempt to build a struct or struct-like
643-
enum variant, one of the fields was specified more than once. Each field should
644-
be specified exactly one time.
643+
enum variant, one of the fields was specified more than once. Erroneous code
644+
example:
645+
646+
```
647+
struct Foo {
648+
x: i32
649+
}
650+
651+
fn main() {
652+
let x = Foo { x: 0,
653+
x: 0, // error: field `x` specified more than once
654+
};
655+
}
656+
```
657+
658+
Each field should be specified exactly one time. Example:
659+
660+
```
661+
struct Foo {
662+
x: i32
663+
}
664+
665+
fn main() {
666+
let x = Foo { x: 0 }; // ok!
667+
}
668+
```
645669
"##,
646670

647671
E0063: r##"

0 commit comments

Comments
 (0)