Rust
E0027 Pattern Does Not Mention Fields Fix
A struct pattern has to account for every field in the declaration - bind the ones the code uses, write field: _ for the ones it does not, or close the pattern with .. and let it cover the rest. Leave a field out entirely and the pattern does not compile.
Written November 28, 2026 · Tested with Rust 1.99.1 · 12 min read
- The rule underneath: every field needs a sub-pattern, or a ..
- The first failure: a struct pattern that leaves out a field
- The second failure: the same omission in an enum variant pattern
- The first fix: name every field and bind the ones used
Written November 28, 2026
Tested with Rust 1.99.1
What this guide is
Error E0027 fires when a pattern for a struct - or for an enum variant with named fields - fails to specify a sub-pattern for every one of the declaration's fields. Destructuring Point { x: i32, y: i32 } with let Point { x } = p; says nothing about y: the pattern neither binds it, nor ignores it, nor covers it with the rest pattern. The compiler reads that silence as a mistake rather than a choice, and refuses to compile until every field is accounted for.
This guide reproduces the error twice - on a plain struct in a let, and on a struct variant in an if let - and then gives the three repairs the compiler itself offers: include the missing field, explicitly ignore it with field: _, or always ignore missing fields with ... The last sections separate the two cases that sound similar but carry different codes: a struct literal that is missing a field is E0063, and a tuple variant pattern with the wrong number of subpatterns is E0023.
The rule underneath: every field needs a sub-pattern, or a ..
The Rust Reference's patterns chapter states the rule directly: if .. is not used, a struct pattern used to match a struct is required to specify all fields. Each field gets a sub-pattern - a binding such as y, a renamed binding such as y: height, a literal, or the wildcard _. The shorthand Point { x } is Point { x: x }: the field name written once binds the field to a variable of the same name.
The two ways to leave a field unbound are different in kind. The wildcard _ stands in for a single data field, and it is written next to that field's name - y: _ names y and discards its value. The rest pattern .. stands in for all the remaining fields of the struct or variant, however many there are, and binds none of them. A pattern with a .. in it has accounted for everything by construction, so it can never raise E0027; a pattern without one must list every field by name.
The first failure: a struct pattern that leaves out a field
struct Point {
x: i32,
y: i32,
}
fn main() {
let p = Point { x: 3, y: 4 };
let Point { x } = p;
println!("x {}", x);
}
$ rustc --edition 2021 p1_fail_struct.rs -o p1_fail_struct.bin
error[E0027]: pattern does not mention field `y`
--> p1_fail_struct.rs:8:9
|
8 | let Point { x } = p;
| ^^^^^^^^^^^ missing field `y`
|
help: include the missing field in the pattern
|
8 | let Point { x, y } = p;
| +++
help: if you don't care about this missing field, you can explicitly ignore it
|
8 | let Point { x, y: _ } = p;
| ++++++
help: or always ignore missing fields here
|
8 | let Point { x, .. } = p;
| ++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0027`.
The span under the whole pattern carries the note "missing field y", and the three helps are the three repairs, in order: add the field, add the field with an explicit ignore, or add ... Nothing else in the program is wrong - the construction on the line above supplies both fields. Only the pattern is incomplete. When several fields are missing, the error names the pattern's omissions the same way; the repair is the same choice, applied to the pattern as a whole.
The second failure: the same omission in an enum variant pattern
A struct variant's pattern follows the same rule, field by field, for that variant's fields:
enum Shape {
Circle { radius: u32, filled: bool },
Square,
}
fn main() {
let s = Shape::Circle { radius: 5, filled: true };
if let Shape::Circle { radius } = s {
println!("circle radius {}", radius);
}
}
$ rustc --edition 2021 p2_fail_variant.rs -o p2_fail_variant.bin
error[E0027]: pattern does not mention field `filled`
--> p2_fail_variant.rs:8:12
|
8 | if let Shape::Circle { radius } = s {
| ^^^^^^^^^^^^^^^^^^^^^^^^ missing field `filled`
|
help: include the missing field in the pattern
|
8 | if let Shape::Circle { radius, filled } = s {
| ++++++++
help: if you don't care about this missing field, you can explicitly ignore it
|
8 | if let Shape::Circle { radius, filled: _ } = s {
| +++++++++++
help: or always ignore missing fields here
|
8 | if let Shape::Circle { radius, .. } = s {
| ++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0027`.
Same code, same three helps, now for the variant's filled field. The accounting is per variant: the pattern has to cover the fields of the variant it names - Circle's two fields here - and the other variants of the enum are not its concern.
The first fix: name every field and bind the ones used
The fullest repair names every field in the pattern. Fields the code needs are bound; the shorthand binds each field to a variable of the same name:
struct Point {
x: i32,
y: i32,
}
fn main() {
let p = Point { x: 3, y: 4 };
let Point { x, y } = p;
println!("x {} y {}", x, y);
}
$ rustc --edition 2021 p3_fix_full.rs -o p3_fix_full.bin
$ ./p3_fix_full.bin
x 3 y 4
This is the right default when the destructuring is the point of the code: every field is visible at the pattern, and if the struct later gains a field, this pattern stops compiling until someone decides what the new field means here. That interruption is information, not friction.
The second fix: name a field only to ignore it
When one field is not needed, name it and discard it in the same breath, with field: _:
struct Point {
x: i32,
y: i32,
}
fn main() {
let p = Point { x: 3, y: 4 };
println!("stored y {}", p.y);
let Point { x, y: _ } = p;
println!("x {}", x);
}
$ rustc --edition 2021 p4_fix_ignore.rs -o p4_fix_ignore.bin
$ ./p4_fix_ignore.bin
stored y 4
x 3
In this program y is read directly off p before the destructuring, so the pattern itself does not need it - but the pattern still has to say so. The y: _ entry is that statement: this field, deliberately unused here. Like the full binding, it names the field, so a future field added to Point makes this pattern raise E0027 again and forces the same decision for the new field. Choose field: _ when the set of fields is part of what the code is asserting.
The third fix: let .. cover the fields not named
The rest pattern accounts for every field not named, all at once:
struct Point {
x: i32,
y: i32,
}
fn main() {
let p = Point { x: 3, y: 4 };
println!("stored y {}", p.y);
let Point { x, .. } = p;
println!("x {}", x);
}
$ rustc --edition 2021 p5_fix_rest.rs -o p5_fix_rest.bin
$ ./p5_fix_rest.bin
stored y 4
x 3
The output matches the previous program, but the contract differs: .. covers y today and would cover a third and fourth field tomorrow without a word. That is the right choice when the unnamed fields are irrelevant as a group - a large struct where the code picks out one field - and the wrong choice when a new field should force a second look. .. can also stand alone, as Point { .. }, matching any value of the type and binding nothing.
The same .. closes a variant pattern. Here each Circle pattern names the one field it uses and lets .. cover the other:
enum Shape {
Circle { radius: u32, filled: bool },
Square,
}
fn main() {
let s = Shape::Circle { radius: 5, filled: true };
if let Shape::Circle { radius, .. } = s {
println!("circle radius {}", radius);
}
let u = Shape::Circle { radius: 9, filled: false };
if let Shape::Circle { filled, .. } = u {
println!("filled {}", filled);
}
let t = Shape::Square;
if let Shape::Square = t {
println!("square");
}
}
$ rustc --edition 2021 p6_fix_variant.rs -o p6_fix_variant.bin
$ ./p6_fix_variant.bin
circle radius 5
filled false
square
The two Circle patterns are mirror images - radius bound with filled covered by .., then filled bound with radius covered - which shows that .. covers whichever fields the pattern leaves unnamed, in any position. The unit variant Square still takes a bare pattern: it has no fields, so there is nothing to account for.
Neighboring error: a struct literal missing a field is E0063
The mirror-image mistake on the construction side is a different error. A struct literal that omits a field is not a pattern at all, and it is reported as E0063:
struct Point {
x: i32,
y: i32,
}
fn main() {
let p = Point { x: 1 };
println!("{} {}", p.x, p.y);
}
$ rustc --edition 2021 p7_neighbour_literal.rs -o p7_neighbour_literal.bin
error[E0063]: missing field `y` in initializer of `Point`
--> p7_neighbour_literal.rs:7:13
|
7 | let p = Point { x: 1 };
| ^^^^^ missing `y`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0063`.
The wording is close - "missing field y" in both - but the positions are opposite. E0063 is about building a value: an initializer must supply every field's value, and the span points at the type name in the literal. E0027 is about taking a value apart: a pattern must mention every field, and the span covers the whole pattern. There is no _ or .. repair for the literal side of this program; the fix is to supply the missing field's value. Read the header's second half to tell them apart: "in initializer of" means E0063, "pattern does not mention" means E0027.
Neighboring error: a tuple variant pattern with too few subpatterns is E0023
Tuple variants have positions instead of field names, and their patterns are counted rather than named. A tuple variant pattern with fewer subpatterns than the variant has fields is E0023, not E0027:
enum Shape {
Circle(u32, bool),
Square,
}
fn main() {
let s = Shape::Circle(5, true);
if let Shape::Circle(radius) = s {
println!("circle radius {}", radius);
}
}
$ rustc --edition 2021 p8_neighbour_tuple.rs -o p8_neighbour_tuple.bin
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
--> p8_neighbour_tuple.rs:8:26
|
2 | Circle(u32, bool),
| --- ---- tuple variant has 2 fields
...
8 | if let Shape::Circle(radius) = s {
| ^^^^^^ expected 2 fields, found 1
|
help: use `_` to explicitly ignore each field
|
8 | if let Shape::Circle(radius, _) = s {
| +++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0023`.
The diagnostic counts: the declaration is annotated field by field, and the pattern's subpattern is marked "expected 2 fields, found 1". The repair matches the counting model - one subpattern per position, with _ for a position the code does not need, as the help shows; a .. can also cover the remaining positions of a tuple pattern. The dividing line is the declaration's shape: named fields are accounted for by name and fall under E0027, numbered positions are accounted for by count and fall under E0023.
Decision summary
- The header says "pattern does not mention field
y" (E0027): a struct or struct-variant pattern left a named field out and has no..- add the field as a binding, add it asfield: _, or add... - The code uses the field's value: bind it, as in
Point { x, y }or the renamed formPoint { x, y: height }. - The code does not use one specific field, and a future field should be flagged too: write
field: _, as inPoint { x, y: _ }- the field is named, so the accounting stays exact. - The fields not named are irrelevant as a group, however many there are: close the pattern with
.., as inPoint { x, .. }orShape::Circle { radius, .. }. - The header instead says "missing field
yin initializer ofPoint" (E0063): the braces are a struct literal, not a pattern - supply the missing field's value in the construction. - The header instead says "this pattern has 1 field, but the corresponding tuple variant has 2 fields" (E0023): the variant's fields are positions, not names - give the pattern one subpattern per position,
_for positions not needed.
Checklist
- Every struct pattern and struct-variant pattern names every field of the declaration, or ends with
... - Each named field is either bound under a name the code uses, renamed on purpose, or written as
field: _on purpose - no field is silently absent. - The choice between
field: _and..is deliberate:_keeps the accounting exact per field,..absorbs fields not yet written as well. - Tuple variant patterns carry one subpattern per position, with
_or..covering the positions not bound. - Struct literals supply every field's value - a missing value in a literal is E0063, fixed in the construction, not the pattern.
- The fixed programs compile, run, and their output shows the bound field values where the code prints them.
Related guides
- E0063 Missing Fields in Struct Fix - the construction-side counterpart: the braces are a literal building a value, and a field's value is missing from it.
- E0533 Expected Value, Found Variant Fix - the neighboring variant-pattern error: a struct variant named bare in a pattern, with no braces at all, fixed by adding the field names.
- E0532 Expected Tuple Variant Fix - the pattern-side sibling for tuple variants: a struct-style pattern used where the declaration has positions, fixed by matching the declaration's shape.
Sources
- Rust, Error codes index: E0027 - the definition of the error: a pattern for a struct fails to specify a sub-pattern for every one of the struct's fields; its example destructures a
Dog { name, age }with a pattern naming onlyage, and its stated fix is to ensure each field from the struct's definition is mentioned in the pattern, or use..to ignore unwanted fields. - The Rust Reference, Patterns - the pattern kinds and their accounting: struct patterns match struct, enum, and union values by named fields, and if
..is not used, a struct pattern used to match a struct is required to specify all fields; the wildcard_stands in for a single data field, while the rest pattern..stands in for all the remaining fields - the rule E0027 enforces and the distinction the three fixes rest on.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.