Error codes

E0264: wrong number of fields in a variant pattern

In a terminal: auk explain E0264 prints this page.

On this page

A variant pattern must list one pattern per field of the variant (use _ for fields you don't need). The message says how many the variant has.

Wrong#

auk
enum Shape { Rect(w: int, h: int) }
fn width(s: Shape): int = match s {
  Rect(w) => w
}

Fixed#

auk
enum Shape { Rect(w: int, h: int) }
fn width(s: Shape): int = match s {
  Rect(w, _) => w
}

Common causes#

  • A field added to the variant but not to its patterns.
  • Matching a variant by name alone: Rect needs Rect(_, _).

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