Error codes

E0402: let ... else whose pattern always matches

In a terminal: auk explain E0402 prints this page.

On this page

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#

auk
enum Id { User(n: int) }
fn num(id: Id): int {
  let User(n) = id else { return 0 }
  n
}

Fixed#

auk
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't T? or T! is E0255 instead.
  • Defensive else blocks copied from code where the pattern really could fail.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page