The pattern of this let matches every value of its type, so the else part can never run.
Auk flags dead code like this so it doesn't mislead readers; the fix removes the else.
Wrong#
enum Id { User(n: int) }
fn num(id: Id): int {
let User(n) = id else { return 0 }
n
}Fixed#
enum Id { User(n: int) }
fn num(id: Id): int {
let User(n) = id
n
}Common causes#
- An enum with a single variant: its pattern always matches.
- A plain
let x = v else ...on a value that isn'tT?orT!is E0255 instead. - Defensive
elseblocks copied from code where the pattern really could fail.