Error codes

E0266: struct pattern doesn't mention every field

In a terminal: auk explain E0266 prints this page.

On this page

A struct pattern lists every field, or ends with .. to say "and the others don't matter". This way adding a field to a struct makes you revisit each pattern that names its fields.

Wrong#

auk
struct P { x: int, y: int }
fn getx(p: P): int = match p {
  P { x } => x
}

Fixed#

auk
struct P { x: int, y: int }
fn getx(p: P): int = match p {
  P { x, .. } => x
}

Common causes#

  • Leaving out the .. when only some fields are needed.
  • A field added to the struct after the pattern was written.

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