Rust

Tuple Pattern Field Count E0023 Fix

E0023 is the compiler counting fields in a pattern. A pattern for a tuple variant or a tuple struct must give one sub-pattern for every field the variant or struct was declared with - no silent omissions, no extras. The diagnostic names both counts, underlines the pattern, and, when fields are missing, offers the underscore repair directly. This guide shows the error too few and too many on a variant and on a tuple struct, the repairs that name, ignore, or rest away the remaining fields, and the neighboring shape that looks identical and is not this error: a plain tuple with the wrong count draws E0308 instead.

Written December 1, 2026 · Tested with Rust 1.99.0 · 18 min read

By the end of this guide
  • The rule underneath: one sub-pattern per declared field
  • How to read the diagnostic
  • The first failure: a tuple variant matched with too few fields
  • The same variant with too many fields

Written December 1, 2026

Tested with Rust 1.99.0

What this guide is

Error E0023 is about patterns that carry their own field list: tuple variants and tuple structs. The error codes index states it in one line - a pattern attempted to extract an incorrect number of fields from a variant - and its example is an enum variant, Fruit::Apple(String, String), matched with one field instead of two. A pattern used against an enum variant must provide a sub-pattern for each field of the variant, and matching with the wrong number of fields has no sensible interpretation.

That scope matters, because the shape that looks most like E0023 is not E0023. A pattern with the wrong number of elements for a plain tuple - let (a, b) = (1, 2, 3); - never draws this code in the probed set: it draws E0308, mismatched types, because a tuple pattern is part of the tuple's type, so the wrong count is a type mismatch. E0023 belongs to the named shapes, where the field count comes from a declaration the compiler can point back at: an enum's tuple variant and a tuple struct. Both families are shown failing and repaired below, and the plain-tuple boundary is shown in full so the two diagnostics are never confused.

The practical payoff is that the repair is counting, not restructuring. Give the pattern exactly as many sub-patterns as the declaration has fields - a name for each field you use, an underscore for each field you do not - or close the pattern with a rest pattern, .., when the remaining fields are none of your business. All three repairs are shown running below.

Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line.

The rule underneath: one sub-pattern per declared field

A tuple variant and a tuple struct are both declared with a fixed field list. Apple(String, String) has two fields; struct Pair(i32, i32) has two fields. A pattern against either one is a claim about that list, and the compiler checks the claim exactly: too few sub-patterns leaves a field unaccounted for, too many invents a field that does not exist. There is no defaulting in either direction - an omitted field is not silently ignored, which is why the compiler's own suggested repair for the too-few case is to write the omission down as an underscore.

A plain tuple has no separate declaration to check a claim against. The pattern (a, b) itself has the tuple type (_, _), and matching it against a value of type (i32, i32, i32) is a mismatch between two types. Same counting mistake, different mechanism, different code - the sections below keep the two apart by the span each diagnostic underlines and the header each one prints.

How to read the diagnostic

In the probed set, an E0023 failure is a single error. The header states both counts in the compiler's current wording: "this pattern has 1 field, but the corresponding tuple variant has 2 fields" - "tuple struct" in the second clause when the pattern names a tuple struct. The span points back at the declaration, underlining each declared field, and underlines the pattern's fields with a label of the form "expected 2 fields, found 1".

The too-few and too-many cases differ in one visible way. When fields are missing, the diagnostic carries a help section - "use _ to explicitly ignore each field" - with the pattern rewritten with one underscore added per missing field. When two or more fields are missing, it carries a second help section as well - "use .. to ignore the rest of the fields" - with the pattern rewritten with a rest pattern instead; with no fields named at all, that second help is worded "use .. to ignore all fields". When the pattern has too many fields, there is no help section in the probed output: there is nothing to add, and the repair is to delete the extra sub-patterns (or replace the tail with ..). Read the two numbers in the header first; they say which of those two repairs you are doing.

The first failure: a tuple variant matched with too few fields

The smallest shape is the index's own example - a two-field variant matched with one field in a match arm, with the bound field printed in the arm that would have run:

Rust
enum Fruit {
    Apple(String, String),
    Pear(u32),
}
fn main() {
    let x = Fruit::Apple(String::from("a"), String::from("b"));
    match x {
        Fruit::Apple(a) => println!("{}", a),
        _ => println!("other"),
    }
}
Output
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
 --> fail_enum_tuple_too_few.rs:8:22
  |
2 |     Apple(String, String),
  |           ------  ------ tuple variant has 2 fields
...
8 |         Fruit::Apple(a) => println!("{}", a),
  |                      ^ expected 2 fields, found 1
  |
help: use `_` to explicitly ignore each field
  |
8 |         Fruit::Apple(a, _) => println!("{}", a),
  |                       +++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0023`.

Nothing is wrong with the variant, with String, or with the match. The one defect is the count: the pattern names one field and the declaration has two. The second field is not ignored by being left out - leaving it out is the error. The index is explicit that the correct form names both fields, and the compiler's help line shows the other correct form, naming one and underscoring the other; both are shown running below.

The same variant with too many fields

Adding a field the variant does not have fails the same way, with the counts reversed and, as noted above, no help section:

Rust
enum Fruit {
    Apple(String, String),
    Pear(u32),
}
fn main() {
    let x = Fruit::Apple(String::from("a"), String::from("b"));
    match x {
        Fruit::Apple(a, b, c) => println!("{} {} {}", a, b, c),
        _ => println!("other"),
    }
}
Output
error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields
 --> fail_enum_tuple_too_many.rs:8:22
  |
2 |     Apple(String, String),
  |           ------  ------ tuple variant has 2 fields
...
8 |         Fruit::Apple(a, b, c) => println!("{} {} {}", a, b, c),
  |                      ^  ^  ^ expected 2 fields, found 3

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0023`.

The pattern cannot invent a third field for a two-field variant. Delete the extra sub-pattern, or - when the extras were a guess at a longer variant - re-check the declaration: the header's second number is the declaration's count, and it is the one the pattern must match.

The same error on a tuple struct

A tuple struct draws the identical code, with the header naming the tuple struct instead of the tuple variant. Too few fields, in a let pattern:

Rust
struct Pair(i32, i32);
fn main() {
    let Pair(a) = Pair(1, 2);
    println!("{}", a);
}
Output
error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields
 --> fail_tuple_struct_too_few.rs:3:14
  |
1 | struct Pair(i32, i32);
  |             ---  --- tuple struct has 2 fields
2 | fn main() {
3 |     let Pair(a) = Pair(1, 2);
  |              ^ expected 2 fields, found 1
  |
help: use `_` to explicitly ignore each field
  |
3 |     let Pair(a, _) = Pair(1, 2);
  |               +++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0023`.

Too many fields, in the same position:

Rust
struct Pair(i32, i32);
fn main() {
    let Pair(a, b, c) = Pair(1, 2);
    println!("{} {} {}", a, b, c);
}
Output
error[E0023]: this pattern has 3 fields, but the corresponding tuple struct has 2 fields
 --> fail_tuple_struct_too_many.rs:3:14
  |
1 | struct Pair(i32, i32);
  |             ---  --- tuple struct has 2 fields
2 | fn main() {
3 |     let Pair(a, b, c) = Pair(1, 2);
  |              ^  ^  ^ expected 2 fields, found 3

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0023`.

The position of the pattern does not change the code. The same too-few tuple struct pattern in a match arm draws the same E0023, with the same help line:

Rust
struct Pair(i32, i32);
fn main() {
    match Pair(1, 2) {
        Pair(a) => println!("{}", a),
        Pair(a, b) => println!("{} {}", a, b),
    }
}
Output
error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields
 --> fail_match_tuple_struct_too_few.rs:4:14
  |
1 | struct Pair(i32, i32);
  |             ---  --- tuple struct has 2 fields
...
4 |         Pair(a) => println!("{}", a),
  |              ^ expected 2 fields, found 1
  |
help: use `_` to explicitly ignore each field
  |
4 |         Pair(a, _) => println!("{}", a),
  |               +++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0023`.

The context does not change the code: if let and nesting

For a named shape, E0023 is E0023 wherever the pattern stands. An if let with the too-few variant pattern draws it, identical in form to the match arm:

Rust
enum Fruit {
    Apple(String, String),
    Pear(u32),
}
fn main() {
    let x = Fruit::Apple(String::from("a"), String::from("b"));
    if let Fruit::Apple(a) = x {
        println!("{}", a);
    }
}
Output
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
 --> fail_if_let_enum_too_few.rs:7:25
  |
2 |     Apple(String, String),
  |           ------  ------ tuple variant has 2 fields
...
7 |     if let Fruit::Apple(a) = x {
  |                         ^ expected 2 fields, found 1
  |
help: use `_` to explicitly ignore each field
  |
7 |     if let Fruit::Apple(a, _) = x {
  |                          +++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0023`.

And the error survives nesting. A variant pattern with the wrong count inside an otherwise correct tuple pattern draws E0023 at the inner pattern - the outer tuple's count is right, and the compiler says nothing about it:

Rust
#[allow(dead_code)]
enum Fruit {
    Apple(String, String),
    Pear(u32),
}
fn main() {
    let x = (Fruit::Apple(String::from("a"), String::from("b")), 4);
    let (Fruit::Apple(a), c) = x;
    println!("{} {}", a, c);
}
Output
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
 --> fail_nested_enum_variant.rs:8:23
  |
3 |     Apple(String, String),
  |           ------  ------ tuple variant has 2 fields
...
8 |     let (Fruit::Apple(a), c) = x;
  |                       ^ expected 2 fields, found 1
  |
help: use `_` to explicitly ignore each field
  |
8 |     let (Fruit::Apple(a, _), c) = x;
  |                        +++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0023`.

So there is no refutability split in the probed set: let, if let, and match all draw E0023 for a variant or tuple struct pattern with the wrong count. What changes the code is not where the pattern stands but what it names - which is the boundary in the next section.

The boundary: a plain tuple with the wrong count draws E0308

A plain tuple pattern with too few elements, in the same let position as the tuple struct failure above, is a type error, not a field-count error:

Rust
fn main() {
    let (a, b) = (1, 2, 3);
    println!("{} {}", a, b);
}
Output
error[E0308]: mismatched types
 --> fail_let_too_few.rs:2:9
  |
2 |     let (a, b) = (1, 2, 3);
  |         ^^^^^^   --------- this expression has type `({integer}, {integer}, {integer})`
  |         |
  |         expected a tuple with 3 elements, found one with 2 elements
  |
  = note: expected tuple `({integer}, {integer}, {integer})`
             found tuple `(_, _)`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.

The header is "mismatched types", the span labels the pattern "expected a tuple with 3 elements, found one with 2 elements", and the note gives the two tuple types. Too many elements reverses the counts and changes nothing else. In a match arm the same shape draws the same code:

Rust
fn main() {
    let x = (1, 2, 3);
    match x {
        (a, b) => println!("{} {}", a, b),
        _ => println!("other"),
    }
}
Output
error[E0308]: mismatched types
 --> fail_match_too_few.rs:4:9
  |
3 |     match x {
  |           - this expression has type `({integer}, {integer}, {integer})`
4 |         (a, b) => println!("{} {}", a, b),
  |         ^^^^^^ expected a tuple with 3 elements, found one with 2 elements
  |
  = note: expected tuple `({integer}, {integer}, {integer})`
             found tuple `(_, _)`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.

And in a function parameter pattern - a position where the pattern is checked against the declared parameter type - the same code again:

Rust
fn show((a, b): (i32, i32, i32)) {
    println!("{} {}", a, b);
}
fn main() {
    show((1, 2, 3));
}
Output
error[E0308]: mismatched types
 --> fail_fn_param_too_few.rs:1:9
  |
1 | fn show((a, b): (i32, i32, i32)) {
  |         ^^^^^^  --------------- expected due to this
  |         |
  |         expected a tuple with 3 elements, found one with 2 elements
  |
  = note: expected tuple `(i32, i32, i32)`
             found tuple `(_, _)`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.

The rest of the plain-tuple family behaved identically in the probed set, each drawing E0308 as a single error: a match arm with too many elements, a function parameter with too many elements, a closure parameter pattern with too few elements, a for loop pattern with too few elements, and a nested tuple pattern whose inner tuple has the wrong count, in both directions. The nested case is the sharpest contrast with the section above: nest a plain tuple inside a tuple and the inner miscount is E0308; nest a tuple variant inside a tuple and the inner miscount is E0023. The code follows the inner shape's kind, not the nesting.

Diagnosis follows from that split. If your header says "mismatched types" and the note shows two tuple types, fix the pattern and the value's type to agree in count - the repairs below for plain tuples are the same counting repairs, but no E0023 wording will appear in the output. If your header gives a pattern count and a variant or tuple struct count, you are in E0023 and the declaration is the authority.

The repair: give the pattern the declared count

The index's correct form is the whole repair for code that uses every field: name one sub-pattern per field. On the variant:

Rust
#[allow(dead_code)]
enum Fruit {
    Apple(String, String),
    Pear(u32),
}
fn main() {
    let x = Fruit::Apple(String::from("a"), String::from("b"));
    match x {
        Fruit::Apple(a, b) => println!("{} {}", a, b),
        _ => println!("other"),
    }
}
Output
a b

The output is a b - both fields bound and printed, in declaration order. On a plain tuple, the correct-count form is the corresponding control:

Rust
fn main() {
    let (a, b, c) = (1, 2, 3);
    println!("{} {} {}", a, b, c);
}
Output
1 2 3

The output is 1 2 3. And on the tuple struct, the correct count in a let:

Rust
struct Pair(i32, i32);
fn main() {
    let Pair(a, b) = Pair(1, 2);
    println!("{} {}", a, b);
}
Output
1 2

The output is 1 2. In each family the repair is the same act - count the declaration (or the tuple type), then write that many sub-patterns - and the code that results compiles with nothing left over.

The repair the compiler suggests: an underscore per ignored field

When a field is not used, the too-few diagnostic's help line is the repair: keep the count, and write _ for each field you are ignoring. On a plain tuple the shape is:

Rust
fn main() {
    let (a, _, _) = (1, 2, 3);
    println!("{}", a);
}
Output
1

The output is 1 - the first element bound, the other two explicitly ignored, and the count still three. Applied to the variant, this is exactly the compiler's suggested rewrite, Fruit::Apple(a, _); applied to the tuple struct, it is Pair(a, _). The underscore is a sub-pattern, so the count the compiler checks includes it - that is why it repairs the error instead of merely silencing it.

The repair for a tail you do not care about: the rest pattern

When everything after a point is irrelevant, one rest pattern, .., accounts for all the remaining fields at once. In a plain tuple let:

Rust
fn main() {
    let (a, ..) = (1, 2, 3);
    println!("{}", a);
}
Output
1

The output is 1. The rest pattern can also sit in the middle, binding fields on both sides of it:

Rust
fn main() {
    let (a, .., c) = (1, 2, 3);
    println!("{} {}", a, c);
}
Output
1 3

The output is 1 3 - the first and last elements bound, the middle element covered by ... On the variant, the rest pattern closes the pattern after the field that is used:

Rust
#[allow(dead_code)]
enum Fruit {
    Apple(String, String),
    Pear(u32),
}
fn main() {
    let x = Fruit::Apple(String::from("a"), String::from("b"));
    match x {
        Fruit::Apple(a, ..) => println!("{}", a),
        _ => println!("other"),
    }
}
Output
a

The output is a, the first field. On the tuple struct, the same form:

Rust
#[allow(dead_code)]
struct Pair(i32, i32);
fn main() {
    let Pair(a, ..) = Pair(1, 2);
    println!("{}", a);
}
Output
1

The output is 1. And in a function parameter pattern - the position that drew E0308 with a plain wrong count - a rest pattern makes a partial binding legal:

Rust
fn show((a, ..): (i32, i32, i32)) {
    println!("{}", a);
}
fn main() {
    show((1, 2, 3));
}
Output
1

The output is 1, printed by a function whose parameter pattern binds only the first element of a three-element tuple. Choose between the two partial repairs by intent: underscores name each ignored field, so a later field added to the declaration still has to be accounted for; .. absorbs any number of remaining fields, including fields added later.

Fixes in reach order

First, read the header. "This pattern has N fields, but the corresponding tuple variant / tuple struct has M fields" is E0023 - the declaration's count, M, is the target. "Mismatched types" with two tuple types in the note is E0308 - the pattern's count and the tuple type's count must be made to agree. The repair counting is the same; the authority differs.

Second, if the pattern is short and you use the missing fields, add a name for each one. If you do not use them, add one _ per missing field - that is the compiler's own suggested rewrite in the too-few diagnostic.

Third, if the pattern is long, delete sub-patterns until it matches the declaration. There is no help line in the too-many diagnostic because there is nothing to add.

Last, if a whole tail is irrelevant - now and after plausible changes to the declaration - replace the tail with ... Prefer underscores when the ignored fields are a fixed, known set; prefer .. when the tail is genuinely "the rest, whatever it is".

Neighboring pattern errors are different codes and different guides: a struct pattern that omits a named field draws E0027, a match that does not cover every value draws E0004, and a pattern used where a tuple variant was expected in a different shape draws E0532. None of those is repaired by recounting a tuple pattern.

Decision summary

E0023, in this guide's probed set, fired exactly when a pattern for a tuple variant or a tuple struct gave the wrong number of fields: too few and too many on an enum tuple variant in a match arm, too few in an if let, too few nested inside a tuple pattern, and too few and too many on a tuple struct in a let and in a match arm. Every diagnostic was a single error headed "this pattern has N field(s), but the corresponding tuple variant / tuple struct has M fields", pointing back at the declaration, with a help line offering an underscore per missing field in the too-few cases - plus, when two or more fields are missing, a second help line offering .. for the rest - and no help line in the too-many cases. The same wrong count on a plain tuple never drew E0023 in the probed set: in a let, a match arm, a function parameter, a closure parameter, a for loop, and a nested tuple pattern, in both directions, it drew E0308, mismatched types. Compiling and running were: correct-count patterns on a variant, a tuple, and a tuple struct; an underscore per ignored field on a tuple; rest patterns at the end and in the middle of a tuple, at the end of a variant pattern and a tuple struct pattern, and in a function parameter pattern.

Checklist

  • Read the header: a pattern count against a variant or tuple struct count is E0023; two tuple types in a note is E0308.
  • Count the declaration first - the pattern must give exactly that many sub-patterns.
  • Too few and you use the fields: add a name per missing field. Too few and you do not: add one _ per missing field.
  • Too many: delete the extra sub-patterns; no diagnostic help line covers this direction.
  • Use .. for a tail that is irrelevant as a whole; use underscores when each ignored field should stay visible.
  • Nesting changes nothing: an inner variant miscount is E0023, an inner plain-tuple miscount is E0308.
  • A struct pattern missing a named field is E0027, not this error - do not recount a tuple pattern to fix it.

Sources

  • Rust error codes index, E0023 - a pattern attempted to extract an incorrect number of fields from a variant; a pattern against an enum variant must provide a sub-pattern for each field of the variant; matching with the wrong number of fields has no sensible interpretation; and the correct form naming both fields of the two-field variant.
  • Rust error codes index, E0308 - mismatched types; the code a plain tuple pattern with the wrong number of elements draws.
  • Rust error codes index, E0027 - a pattern does not mention one or more fields of a struct pattern, the neighboring named-field error.

Keep Exploring