V4001 non_exhaustive_match
A match does not cover every value.
An error from the pattern phase. sakura explain V4001 prints this explanation offline.
A match does not cover every value. The diagnostic names a witness value that no arm
matches. Guards never count toward coverage (design §4.10).
Wrong:
match o { Some(n) if n >= 0 => n }Fixed:
match o { Some(n) if n >= 0 => n, _ => 0 }Wrong program
compiler/tests/ui/V4001_non_exhaustive_match.sakura, which the compiler's ui suite runs through sakura check:
error ParseError(input: String)
fn parse_age(s: String) -> Int ! {Fail<ParseError>} {
match String.parse_int(s) {
Some(n) if n >= 0 => n,
Some(_) => fail ParseError { input: s },
}
}sakura check --json reports this record (pretty-printed; $DIR is the fixture's directory):
{
"schema_version": "1.0",
"kind": "diagnostic",
"id": "d:029a0b367e63284d",
"code": "V4001",
"severity": "error",
"phase": "pattern",
"message": "non-exhaustive match: `None` not covered",
"snapshot": "sha256:$SNAPSHOT",
"symbol_id": "main::V4001_non_exhaustive_match::parse_age",
"spans": [
{
"uri": "file://$DIR/V4001_non_exhaustive_match.sakura",
"content_hash": "sha256:a85cd0432d080f202e1a76e4e6c322d610e6c4d89ced36170bc83516ba2643f3",
"start_byte": 123,
"end_byte": 227,
"role": "primary"
}
],
"related_ids": [],
"expected": null,
"actual": {
"render": "None"
},
"obligation": null,
"counterexample": null,
"explanation_uri": "sakura://explain/V4001",
"fixes": [
{
"id": "f:029a0b367e63284d.0",
"title": "Add an arm for `None`",
"applicability": "incomplete",
"impact": "behavior_change",
"edits": []
}
]
}Fixed program
compiler/tests/ui/V4001_non_exhaustive_match.fixed.sakura, which sakura check accepts with no diagnostics:
error ParseError(input: String)
fn parse_age(s: String) -> Int ! {Fail<ParseError>} {
match String.parse_int(s) {
Some(n) if n >= 0 => n,
Some(_) => fail ParseError { input: s },
None => fail ParseError { input: s },
}
}