compiler/rustc_error_codes/src/error_codes/E0004.md MARKDOWN 47 lines View on github.com → Search inside
1This error indicates that the compiler cannot guarantee a matching pattern for2one or more possible inputs to a match expression. Guaranteed matches are3required in order to assign values to match expressions, or alternatively,4determine the flow of execution.56Erroneous code example:78```compile_fail,E00049enum Terminator {10    HastaLaVistaBaby,11    TalkToMyHand,12}1314let x = Terminator::HastaLaVistaBaby;1516match x { // error: non-exhaustive patterns: `HastaLaVistaBaby` not covered17    Terminator::TalkToMyHand => {}18}19```2021If you encounter this error you must alter your patterns so that every possible22value of the input type is matched. For types with a small number of variants23(like enums) you should probably cover all cases explicitly. Alternatively, the24underscore `_` wildcard pattern can be added after all other patterns to match25"anything else". Example:2627```28enum Terminator {29    HastaLaVistaBaby,30    TalkToMyHand,31}3233let x = Terminator::HastaLaVistaBaby;3435match x {36    Terminator::TalkToMyHand => {}37    Terminator::HastaLaVistaBaby => {}38}3940// or:4142match x {43    Terminator::TalkToMyHand => {}44    _ => {}45}46```

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.