21.3 Refutable vs. Irrefutable Patterns

Rust distinguishes between refutable and irrefutable patterns:

  • Refutable Patterns might fail to match. An example is Some(x), which does not match None.
  • Irrefutable Patterns are guaranteed to match. For instance, let x = 5; always succeeds in binding 5 to x.

Refutable patterns are only allowed where there is a way to handle a failed match: match arms, if let, while let, or let else. In contrast, irrefutable patterns occur in places that cannot handle a mismatch (e.g., a normal let binding or function parameters).