Skip to content

Rust Error E0027: Pattern Does Not Mention Field X

E0027 means: you’re taking a struct or enum variant apart with a pattern, like let Order { item, quantity } = order;, and you didn’t mention every field. In Rust a struct pattern must account for all fields, either by naming them or by saying “and the rest” with ... This is one of the friendliest errors there is: rustc prints the exact fix, and it’s almost always two dots. (This page is part of Rust compiler errors explained.)

error[E0027]: pattern does not mention fields `id`, `paid`
--> src/main.rs:10:9
|
10 | let Order { item, quantity } = order; // ❌ `id` and `paid` are not mentioned
| ^^^^^^^^^^^^^^^^^^^^^^^^ missing fields `id`, `paid`
|
help: include the missing fields in the pattern
|
10 | let Order { item, quantity, id, paid } = order; // ❌ `id` and `paid` are not mentioned
| ++++++++++
help: if you don't care about these missing fields, you can explicitly ignore them
|
10 | let Order { item, quantity, id: _, paid: _ } = order; // ❌ `id` and `paid` are not mentioned
| ++++++++++++++++
help: or always ignore missing fields here
|
10 | let Order { item, quantity, .. } = order; // ❌ `id` and `paid` are not mentioned
| ++++

This is the program that produces it:

struct Order {
id: u32,
item: String,
quantity: u32,
paid: bool,
}
fn main() {
let order = Order { id: 1, item: String::from("keyboard"), quantity: 2, paid: true };
let Order { item, quantity } = order; // ❌ `id` and `paid` are not mentioned
println!("{} x {}", quantity, item);
}

The headline lists the fields your pattern left out (id and paid). The ^^^ underlines the whole pattern, because the problem isn’t one wrong word, it’s something missing.

Then rustc gives three help: suggestions. They’re all valid, and they mean different things:

  • include the missing fields: name them, so you get variables id and paid too.
  • explicitly ignore them: write id: _, paid: _. You don’t get variables, but you’ve listed every field by name.
  • always ignore missing fields here: write ... It means “and any other fields, I don’t care about them”.

It’s like a checklist at the door that says “tick every box, or tick Other: skip”. You can’t just leave boxes blank.

A struct pattern in Rust is meant to be complete unless you say otherwise. This makes your intent clear to the next reader. Order { item, quantity, .. } says “I only need these two”. Order { id, item, quantity, paid } says “I’ve thought about every field”. See Ignoring parts with _ and ...

The real payoff comes when the struct changes. If someone adds a discount field to Order, a pattern that lists every field by name breaks with E0027, which points you at code that may need to handle the new field. A pattern with .. keeps compiling. Rust lets you choose which behavior you want, but it won’t guess for you.

Choose this most of the time. If you only need some fields, end the pattern with ... It works in let, match, if let and function parameters, and it must come last.

struct Order {
id: u32,
item: String,
quantity: u32,
paid: bool,
}
fn main() {
let order = Order { id: 1, item: String::from("keyboard"), quantity: 2, paid: true };
let Order { item, quantity, .. } = order; // ✅ `..` skips `id` and `paid`
println!("{} x {}", quantity, item);
let orders = [
Order { id: 2, item: String::from("mouse"), quantity: 1, paid: false },
Order { id: 3, item: String::from("monitor"), quantity: 1, paid: true },
];
for order in &orders {
match order {
Order { paid: true, item, .. } => println!("ship the {}", item),
Order { id, .. } => println!("order #{} is waiting for payment", id),
}
}
}

Output:

2 x keyboard
order #2 is waiting for payment
ship the monitor
▶ Try it Yourself

Notice paid: true in the first arm: a field in a pattern can also be checked against a value, and .. still takes care of the others.

Fix 2: Name the missing field, or ignore it by name with _

Section titled “Fix 2: Name the missing field, or ignore it by name with _”

Choose this when you actually need the field, or when you want the pattern to break if a field is added later. The same error appears in a match on an enum variant with named fields:

error[E0027]: pattern does not mention field `y`
--> src/main.rs:9:9
|
9 | Message::Move { x } => println!("move to x = {}", x), // ❌ `y` is not mentioned
| ^^^^^^^^^^^^^^^^^^^ missing field `y`

The program behind it:

enum Message {
Move { x: i32, y: i32 },
Quit,
}
fn main() {
let m = Message::Move { x: 1, y: 2 };
match m {
Message::Move { x } => println!("move to x = {}", x), // ❌ `y` is not mentioned
Message::Quit => println!("quit"),
}
}

A move has two coordinates, and the code should really use both. So name y. When a field truly doesn’t matter, y: _ says so out loud, and still lists it by name:

enum Message {
Move { x: i32, y: i32 },
Quit,
}
fn main() {
let messages = [Message::Move { x: 1, y: 2 }, Message::Move { x: 5, y: 0 }, Message::Quit];
for m in &messages {
match m {
Message::Move { x, y: 0 } => println!("slide along the floor to x = {}", x),
Message::Move { x, y } => println!("move to ({}, {})", x, y), // ✅ both fields
Message::Quit => println!("quit"),
}
}
// every field listed by name: adding a field to `Move` will break this on purpose
if let Message::Move { x, y: _ } = &messages[0] {
println!("first x = {}", x);
}
}

Output:

move to (1, 2)
slide along the floor to x = 5
quit
first x = 1
▶ Try it Yourself

If you name a field just to ignore it, write y: _, not a plain y. A plain y you never use gives an “unused variable” warning.

Choose this when E0027 comes together with E0026 on the same line. For example, Shape::Circle { r } for a variant whose field is radius gives both: E0026 for r (no such field) and E0027 for radius (not mentioned). rustc’s E0027 help will suggest adding radius next to r, but that’s not what you want. The real fix is to replace the wrong name: Shape::Circle { radius }, or Shape::Circle { radius: r } to keep the short variable name. Then both errors disappear at once. See the E0026 page for examples.

After adding a field to a struct. You add created_at to Order, and every pattern that listed all fields now gives E0027. That’s the check doing its job. Decide for each one: does this code need created_at? If yes, name it; if not, add ...

Function parameters. fn print_order(&Order { item, quantity }: &Order) gives E0027 too. Fix: &Order { item, quantity, .. }. See Patterns in let and function parameters.

Tuple structs and tuple variants. For struct Color(u8, u8, u8);, the pattern Color(r) is also incomplete, but rustc reports it as E0023, “this pattern has 1 field, but the corresponding tuple struct has 3 fields”. The fix is the same idea: Color(r, ..) or Color(r, _, _).

Quick check

1. struct Point { x: i32, y: i32, z: i32 }. Which pattern compiles and gives you only x?

2. What's the difference between Order { item, .. } and Order { item, id: _, quantity: _, paid: _ }?

3. You get E0026 for r and E0027 for radius on the same line. What's the best fix?

Score: 0 / 3