E1046: pattern can never match
Branches of a case are tried from top to bottom.
Branches of a case are tried from top to bottom. A branch that follows an
unguarded _ branch is never reached, because _ already matches every
value. The compiler rejects the dead branch. The message shows the pattern,
and the error points at it.
A _ branch that follows unguarded branches naming every variant of an enum,
or both true and false of a Bool, is just as dead: nothing is left for
it to match. The error points at the _. A _ that covers at least one value
no branch names is accepted, and a branch with a guard does not name its
value.
Example
Fix
Put the _ branch last, or remove it when the branches before it cover every value.
actus check --format json offers this as a fix: remove the unreachable arm, with its trailing comma and the line break before it (a review fix, because it deletes code).
Run actus explain E1046 in your terminal to read this entry offline. Browse Ownership & types or all error codes.