Email me

Rust errors / Names, paths and imports

Rust compiler error · checked with rustc 1.99.0

Rust error E0027: pattern does not mention field `name`

What it meansA pattern for a struct fails to specify a sub-pattern for every one of the struct's fields.

What rustc prints

error[E0027]: pattern does not mention field `name`
  --> main.rs:12:5
   |
12 |     Dog { age: x } => {}
   |     ^^^^^^^^^^^^^^ missing field `name`
   |
help: include the missing field in the pattern
   |
12 |     Dog { age: x, name } => {}
   |                 ++++++
help: if you don't care about this missing field, you can explicitly ignore it
   |
12 |     Dog { age: x, name: _ } => {}
   |                 +++++++++
help: or always ignore missing fields here
   |
12 |     Dog { age: x, .. } => {}
   |                 ++++

Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.

E0027Names, paths and imports
Activein rustc 1.99.0
7related errors linked below

The compiler team's explanation

A pattern for a struct fails to specify a sub-pattern for every one of the struct's fields.

Erroneous code example:

struct Dog {
    name: String,
    age: u32,
}

let d = Dog { name: "Rusty".to_string(), age: 8 };

// This is incorrect.
match d {
    Dog { age: x } => {}
}

To fix this error, ensure that each field from the struct's definition is mentioned in the pattern, or use .. to ignore unwanted fields. Example:

struct Dog {
    name: String,
    age: u32,
}

let d = Dog { name: "Rusty".to_string(), age: 8 };

match d {
    Dog { name: ref n, age: x } => {}
}

// This is also correct (ignore unused fields).
match d {
    Dog { age: x, .. } => {}
}

From rustc --explain E0027 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.

Related errors

All 518 Rust error codes · Rust crate data · Glossary

Up next

Often hit nextE0425: cannot find value in this scopeA related error from the same family.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ