From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../rustc_error_codes/src/error_codes/E0023.md | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0023.md (limited to 'compiler/rustc_error_codes/src/error_codes/E0023.md') diff --git a/compiler/rustc_error_codes/src/error_codes/E0023.md b/compiler/rustc_error_codes/src/error_codes/E0023.md new file mode 100644 index 000000000..c1d85705d --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0023.md @@ -0,0 +1,57 @@ +A pattern attempted to extract an incorrect number of fields from a variant. + +Erroneous code example: + +```compile_fail,E0023 +enum Fruit { + Apple(String, String), + Pear(u32), +} + +let x = Fruit::Apple(String::new(), String::new()); + +match x { + Fruit::Apple(a) => {}, // error! + _ => {} +} +``` + +A pattern used to match against an enum variant must provide a sub-pattern for +each field of the enum variant. + +Here the `Apple` variant has two fields, and should be matched against like so: + +``` +enum Fruit { + Apple(String, String), + Pear(u32), +} + +let x = Fruit::Apple(String::new(), String::new()); + +// Correct. +match x { + Fruit::Apple(a, b) => {}, + _ => {} +} +``` + +Matching with the wrong number of fields has no sensible interpretation: + +```compile_fail,E0023 +enum Fruit { + Apple(String, String), + Pear(u32), +} + +let x = Fruit::Apple(String::new(), String::new()); + +// Incorrect. +match x { + Fruit::Apple(a) => {}, + Fruit::Apple(a, b, c) => {}, +} +``` + +Check how many fields the enum was declared with and ensure that your pattern +uses the same number. -- cgit v1.2.3