From aab4276477e84545641b1cf69b43612efa6bf702 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 3 Jan 2020 17:42:56 +0100 Subject: [PATCH] Clean up E0164 explanation --- src/librustc_error_codes/error_codes/E0164.md | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0164.md b/src/librustc_error_codes/error_codes/E0164.md index b41ce6fad8e5..8eb5ace4fe4d 100644 --- a/src/librustc_error_codes/error_codes/E0164.md +++ b/src/librustc_error_codes/error_codes/E0164.md @@ -1,24 +1,44 @@ -This error means that an attempt was made to match a struct type enum -variant as a non-struct type: +Something which is neither a tuple struct nor a tuple variant was used as a +pattern. + +Erroneous code example: ```compile_fail,E0164 -enum Foo { B { i: u32 } } +enum A { + B, + C, +} -fn bar(foo: Foo) -> u32 { +impl A { + fn new() {} +} + +fn bar(foo: A) { match foo { - Foo::B(i) => i, // error E0164 + A::new() => (), // error! + _ => {} } } ``` -Try using `{}` instead: +This error means that an attempt was made to match something which is neither a +tuple struct nor a tuple variant. Only these two elements are allowed as +pattern: ``` -enum Foo { B { i: u32 } } +enum A { + B, + C, +} -fn bar(foo: Foo) -> u32 { +impl A { + fn new() {} +} + +fn bar(foo: A) { match foo { - Foo::B{i} => i, + A::B => (), // ok! + _ => {} } } ```