Skip to content
Playground(another site)

bynk.parse.lambda_pattern_not_record

Error A lambda parameter is a pattern other than a record pattern; only an irrefutable record pattern may stand in for a name.

A lambda parameter may be a pattern only when it is a record pattern that cannot fail, as in (Item { qty, .. }) => qty. A lambda is given a value and has no else, so a pattern that can miss, such as Some(n), a list, a literal or a range, has no way to say what happens then. Take a name and match on it in the body.

Example

xs.map((Some(n)) => n) // ✗ a lambda has no `else` for `None`
xs.map((o) => match o { // ✓ the `match` covers both
Some(n) => n
None => 0
})

In the Book

See also

  • The grammar rule it governs: lambda_param.
  • Every code in its category, Parser, on the diagnostic index.
  • bynk explain bynk.parse.lambda_pattern_not_record shows the same from the installed toolchain, without a network.