From 5d8dc9076bf387398eeac9c50109a15026e22b36 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Aug 2015 13:38:27 +0200 Subject: [PATCH] Improve E0025 error explanation --- src/librustc_typeck/diagnostics.rs | 37 ++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index d03751275c0f..100415c29c67 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -73,10 +73,39 @@ the enum. "##, E0025: r##" -Each field of a struct can only be bound once in a pattern. Each occurrence of a -field name binds the value of that field, so to fix this error you will have to -remove or alter the duplicate uses of the field name. Perhaps you misspelt -another field name? +Each field of a struct can only be bound once in a pattern. Erroneous code +example: + +``` +struct Foo { + a: u8, + b: u8, +} + +fn main(){ + let x = Foo { a:1, b:2 }; + + let Foo { a: x, a: y } = x; + // error: field `a` bound multiple times in the pattern +} +``` + +Each occurrence of a field name binds the value of that field, so to fix this +error you will have to remove or alter the duplicate uses of the field name. +Perhaps you misspelled another field name? Example: + +``` +struct Foo { + a: u8, + b: u8, +} + +fn main(){ + let x = Foo { a:1, b:2 }; + + let Foo { a: x, b: y } = x; // ok! +} +``` "##, E0026: r##"