compiler/rustc_error_codes/src/error_codes/E0023.md MARKDOWN 58 lines View on github.com → Search inside
1A pattern attempted to extract an incorrect number of fields from a variant.23Erroneous code example:45```compile_fail,E00236enum Fruit {7    Apple(String, String),8    Pear(u32),9}1011let x = Fruit::Apple(String::new(), String::new());1213match x {14    Fruit::Apple(a) => {}, // error!15    _ => {}16}17```1819A pattern used to match against an enum variant must provide a sub-pattern for20each field of the enum variant.2122Here the `Apple` variant has two fields, and should be matched against like so:2324```25enum Fruit {26    Apple(String, String),27    Pear(u32),28}2930let x = Fruit::Apple(String::new(), String::new());3132// Correct.33match x {34    Fruit::Apple(a, b) => {},35    _ => {}36}37```3839Matching with the wrong number of fields has no sensible interpretation:4041```compile_fail,E002342enum Fruit {43    Apple(String, String),44    Pear(u32),45}4647let x = Fruit::Apple(String::new(), String::new());4849// Incorrect.50match x {51    Fruit::Apple(a) => {},52    Fruit::Apple(a, b, c) => {},53}54```5556Check how many fields the enum was declared with and ensure that your pattern57uses the same number.

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.