Rust

Field Specified More Than Once E0062 Fix

A struct literal gives each field exactly one value. Naming the same field twice in one literal - even with the same value, even in shorthand, even next to a .. base - draws E0062, and the compiler points at the second use. The fix is to name the field once: remove the duplicate, or set the field in the literal and assign any later value after construction. This guide shows each repeated-field shape failing, the neighboring mistakes that draw different codes, the same-name shapes that are legal, and the repairs running.

Written December 2, 2026 · Tested with Rust 1.99.0 · 16 min read

By the end of this guide
  • The rule underneath: one value per field in one literal
  • How to read the diagnostic
  • The first failure: the index example
  • Every repeated-field shape draws the same code

Written December 2, 2026

Tested with Rust 1.99.0

What this guide is

Error E0062 means a field was specified more than once while building a struct or a struct-like enum variant. The error codes index puts it in one line: "A struct's or struct-like enum variant's field was specified more than once."

The boundary around that line is what decides the fix. The duplicate has to sit in one literal: the same field named twice in a struct definition draws E0124, and the same field bound twice in a destructuring pattern draws E0025. Naming a field once and letting functional update syntax (..base) supply the rest is legal, and the explicitly named field wins over the base. This guide shows each case with its actual code.

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 value per field in one literal

A struct literal is a complete construction: every field of the struct gets its value from that one expression. A field named twice leaves two candidate values for one slot, and the compiler rejects the literal rather than picking one - it does not matter that the two values are equal, and it does not matter that they differ. Changing the second value is not a fix; removing the second mention is.

The count is per literal, not per program. Two different structs may each declare a field named x, and one function may build both, because each literal names its own struct's field once. The sections below show that shape compiling and running next to the failing ones.

How to read the diagnostic

The header names the field: "field x specified more than once". Two spans follow. The first mention in the literal is labeled "first use of x", and the second mention - the one the error points at - is labeled "used more than once". The repair is applied to the second mention: delete it, or move its value into an assignment after construction. The first mention is the definition the literal keeps.

One reading trap matters: a field named three times draws the error twice, once for the second mention and once for the third, each pointing back to the same first use. Count the errors before assuming two different fields are involved.

The first failure: the index example

The index's erroneous example, verbatim:

Rust
struct Foo {
    x: i32,
}

fn main() {
    let x = Foo {
                x: 0,
                x: 0, // error: field `x` specified more than once
            };
}
Output
error[E0062]: field `x` specified more than once
 --> fail_index.rs:8:17
  |
7 |                 x: 0,
  |                 ---- first use of `x`
8 |                 x: 0, // error: field `x` specified more than once
  |                 ^ used more than once

error: aborting due to 1 previous error

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

The two values are identical - both are 0 - and the literal still fails. Equality is not a way out, because the defect is the repeated name, not a disagreement between values. The index's corrected form names the field once, let x = Foo { x: 0 };, and that shape is shown running in the repairs below.

Every repeated-field shape draws the same code

A different second value changes nothing. The literal below wants x to end up as 2, written the way a sequential reading suggests, and it fails the same way:

Rust
struct Foo {
    x: i32,
    y: i32,
}

fn main() {
    let f = Foo { x: 0, y: 1, x: 2 };
    println!("{}", f.x);
}
Output
error[E0062]: field `x` specified more than once
 --> fail_dup_diff_values.rs:7:31
  |
7 |     let f = Foo { x: 0, y: 1, x: 2 };
  |                   ----        ^ used more than once
  |                   |
  |                   first use of `x`

error: aborting due to 1 previous error

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

Field shorthand is the same mention in shorter form. Writing x alone stands for x: x, and a second bare x later in the same literal is a second specification:

Rust
struct Foo {
    x: i32,
    y: i32,
}

fn main() {
    let x = 5;
    let f = Foo { x, y: 1, x };
    println!("{}", f.x);
}
Output
error[E0062]: field `x` specified more than once
 --> fail_dup_shorthand.rs:8:28
  |
8 |     let f = Foo { x, y: 1, x };
  |                   -        ^ used more than once
  |                   |
  |                   first use of `x`

error: aborting due to 1 previous error

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

A struct-like enum variant is built with the same literal syntax, and the same rule applies to its fields:

Rust
enum Shape {
    Rect { width: u32, height: u32 },
    Point,
}

fn main() {
    let s = Shape::Rect { width: 3, height: 4, width: 5 };
    println!("{:?}", std::mem::discriminant(&s));
}
Output
error[E0062]: field `width` specified more than once
 --> fail_dup_enum_variant.rs:7:48
  |
7 |     let s = Shape::Rect { width: 3, height: 4, width: 5 };
  |                           --------             ^^^^^ used more than once
  |                           |
  |                           first use of `width`

error: aborting due to 1 previous error

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

Functional update syntax does not absorb a duplicate. The ..Default::default() at the end supplies only the fields the literal does not name; a field named twice before it still draws E0062:

Rust
#[derive(Default)]
struct Foo {
    x: i32,
    y: i32,
}

fn main() {
    let f = Foo { x: 0, x: 1, ..Default::default() };
    println!("{}", f.x);
}
Output
error[E0062]: field `x` specified more than once
 --> fail_dup_with_update.rs:8:25
  |
8 |     let f = Foo { x: 0, x: 1, ..Default::default() };
  |                   ----  ^ used more than once
  |                   |
  |                   first use of `x`

error: aborting due to 1 previous error

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

And a third mention adds a second error rather than a stronger one. Each extra mention is reported against the first use:

Rust
struct Foo {
    x: i32,
}

fn main() {
    let f = Foo { x: 0, x: 1, x: 2 };
    println!("{}", f.x);
}
Output
error[E0062]: field `x` specified more than once
 --> fail_dup_three_times.rs:6:25
  |
6 |     let f = Foo { x: 0, x: 1, x: 2 };
  |                   ----  ^ used more than once
  |                   |
  |                   first use of `x`

error[E0062]: field `x` specified more than once
 --> fail_dup_three_times.rs:6:31
  |
6 |     let f = Foo { x: 0, x: 1, x: 2 };
  |                   ----        ^ used more than once
  |                   |
  |                   first use of `x`

error: aborting due to 2 previous errors

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

Same value or different, long form or shorthand, plain struct or enum variant, with or without a .. base: the repeated name in one literal is the whole defect.

The shape that is not this error: the same field bound twice in a pattern

Destructuring repeats a field name for a different reason - two bindings wanted from one field - and it draws its own code, E0025:

Rust
struct Foo {
    x: i32,
    y: i32,
}

fn main() {
    let f = Foo { x: 1, y: 2 };
    let Foo { x: a, x: b, y: _ } = f;
    println!("{} {}", a, b);
}
Output
error[E0025]: field `x` bound multiple times in the pattern
 --> neighbour_dup_in_pattern.rs:8:21
  |
8 |     let Foo { x: a, x: b, y: _ } = f;
  |               ----  ^^^^ multiple uses of `x` in pattern
  |               |
  |               first use of `x`

error: aborting due to 1 previous error

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

The wording is close - "bound multiple times in the pattern" against "specified more than once" - and the spans look alike, first use against second use. The code is the tell: E0025 sits on the pattern side of a let, E0062 on the construction side. A pattern binds each field once; to read one field into two variables, bind it once and copy the binding on the next line.

What does work: a named field plus a .. base

Functional update syntax fills the fields the literal does not name, and a field named once in the literal overrides the base's value for that field. Here x comes from the literal and y comes from base:

Rust
struct Foo {
    x: i32,
    y: i32,
}

fn main() {
    let base = Foo { x: 1, y: 2 };
    let f = Foo { x: 9, ..base };
    println!("{} {}", f.x, f.y);
}
Output
9 2

This is the legal shape the failing ..Default::default() example above was reaching for: name each field at most once, and let the base supply only the rest. The base is not a second specification of the named fields - it is the source for the unnamed ones.

What does work: shorthand once, and the same field name on different structs

Shorthand on its own is fine; only the repeat fails. One bare x reads the local variable of the same name:

Rust
struct Foo {
    x: i32,
    y: i32,
}

fn main() {
    let x = 5;
    let f = Foo { x, y: 1 };
    println!("{} {}", f.x, f.y);
}
Output
5 1

And the per-literal count means two structs may share a field name freely. Foo and Bar each declare an x, and one function builds both:

Rust
struct Foo {
    x: i32,
}

struct Bar {
    x: i32,
}

fn main() {
    let a = Foo { x: 1 };
    let b = Bar { x: 2 };
    println!("{} {}", a.x, b.x);
}
Output
1 2

No renaming is needed across types. The name has to be unique inside one literal, not inside the program.

What does work: an enum variant with each field named once

The variant literal that failed above compiles when width appears once. The unused Point variant draws a dead-code warning, not an error, and the program runs:

Rust
enum Shape {
    Rect { width: u32, height: u32 },
    Point,
}

fn area(s: &Shape) -> u32 {
    match s {
        Shape::Rect { width, height } => width * height,
        Shape::Point => 0,
    }
}

fn main() {
    let s = Shape::Rect { width: 3, height: 4 };
    println!("{}", area(&s));
}
Output
warning: variant `Point` is never constructed
 --> ok_enum_variant_once.rs:3:5
  |
1 | enum Shape {
  |      ----- variant in this enum
2 |     Rect { width: u32, height: u32 },
3 |     Point,
  |     ^^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: 1 warning emitted

Output
12

Neighboring codes: E0124, E0063, E0560, and the base that is not last

Four mistakes sit next to E0062 in the same braces and are routinely confused with it. Each keeps its own code - or, in one case, no code at all.

A field declared twice in the struct definition - E0124. The duplicate can be one level up, in the type itself rather than in any literal:

Rust
struct Foo {
    x: i32,
    x: i32,
}

fn main() {
    let f = Foo { x: 0 };
    println!("{}", f.x);
}
Output
error[E0124]: field `x` is already declared
 --> neighbour_dup_in_definition.rs:3:5
  |
2 |     x: i32,
  |     ------ `x` first declared here
3 |     x: i32,
  |     ^^^^^^ field already declared

error: aborting due to 1 previous error

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

The literal in main is innocent; the fix is in the definition, and every literal then follows the corrected field list. E0124 is the duplicate in the declaration, E0062 the duplicate in a construction.

A field left out - E0063. Naming a field too few times is the mirror mistake:

Rust
struct Foo {
    x: i32,
    y: i32,
}

fn main() {
    let f = Foo { x: 0 };
    println!("{}", f.x);
}
Output
error[E0063]: missing field `y` in initializer of `Foo`
 --> neighbour_missing_field.rs:7:13
  |
7 |     let f = Foo { x: 0 };
  |             ^^^ missing `y`

error: aborting due to 1 previous error

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

The codes are adjacent and the fixes are opposite: E0062 wants a mention removed, E0063 wants one added - or a .. base added to supply it, as in the legal shape above.

A field the struct does not have - E0560. A name that is not a field at all is not a duplicate of anything:

Rust
struct Foo {
    x: i32,
}

fn main() {
    let f = Foo { x: 0, z: 1 };
    println!("{}", f.x);
}
Output
error[E0560]: struct `Foo` has no field named `z`
 --> neighbour_unknown_field.rs:6:25
  |
6 |     let f = Foo { x: 0, z: 1 };
  |                         ^ `Foo` does not have this field
  |
  = note: all struct fields are already assigned

error: aborting due to 1 previous error

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

This is the code a typo usually draws: the second x someone meant to write as the next field's name fails as E0062 only when the name it repeats is real; a name that matches no field is E0560.

A base that is not last - an uncoded error. Functional update syntax must close the literal; putting a field after it fails before any field counting happens, and the error carries no E-code:

Rust
#[derive(Default)]
struct Foo {
    x: i32,
    y: i32,
}

fn main() {
    let f = Foo { ..Default::default(), x: 0 };
    println!("{}", f.x);
}
Output
error: cannot use a comma after the base struct
 --> neighbour_update_not_last.rs:8:19
  |
8 |     let f = Foo { ..Default::default(), x: 0 };
  |                   ^^^^^^^^^^^^^^^^^^^^
  |
  = note: the base struct must always be the last field
help: remove this comma
  |
8 -     let f = Foo { ..Default::default(), x: 0 };
8 +     let f = Foo { ..Default::default() x: 0 };
  |

error: aborting due to 1 previous error

Move the .. base to the end of the literal - Foo { x: 0, ..Default::default() } - and the literal is judged on its fields again.

The repairs

Remove the duplicate. This is the repair when the second mention was a leftover - a paste, a stale line, or an accidental repeat. Keep the mention carrying the value the construction is supposed to have. The index example's corrected form, printing its field, and the two-field case with the surviving value kept:

Rust
struct Foo {
    x: i32,
}

fn main() {
    let x = Foo { x: 0 }; // ok!
    println!("{}", x.x);
}
Output
0
Rust
struct Foo {
    x: i32,
    y: i32,
}

fn main() {
    let f = Foo { x: 2, y: 1 };
    println!("{} {}", f.x, f.y);
}
Output
2 1

Before deleting, check which of the two values the surrounding code was written against - when the values differ, removal is a behavior choice, not a tidy-up. In the second program the surviving x: 2 is the value the failed literal was trying to reach with its last mention.

Set the field once, then assign. This is the repair when both values do real work in sequence - the field starts at one value and is deliberately replaced. State the replacement as an assignment after construction instead of a second mention inside the literal:

Rust
struct Foo {
    x: i32,
    y: i32,
}

fn main() {
    let mut f = Foo { x: 0, y: 1 };
    f.x = 2;
    println!("{} {}", f.x, f.y);
}
Output
2 1

The output matches what the duplicated literal intended - x ends at 2 - with the order of the two writes stated in program order rather than implied by position in one expression. The binding needs mut, which also marks the replacement for readers.

Fixes in reach order

First, check the code before touching anything. E0062 means one literal names a field twice; a duplicate in the struct definition is E0124, the same field bound twice in a pattern is E0025, a missing field is E0063, an unknown field is E0560, and a .. base that is not last is an uncoded error. The code already tells you which braces to open.

Second, find the two spans in the literal the diagnostic names: the "first use" and the mention labeled "used more than once". Decide which value the field is supposed to have and delete the other mention.

Third, if both values were meant to take effect in sequence, keep the first in the literal, make the binding mutable, and write the second as an assignment after construction.

Fourth, if a .. base is present, leave it last and count only the named fields against the rule - the base supplies the unnamed fields and never excuses a named duplicate.

Last, if the same field name appears in several literals and seems duplicated, check whether the literals build different structs, or whether one of them is a pattern rather than a construction. Those shapes are legal; leave them alone.

Decision summary

E0062 fired for every repeated field inside one construction: the index example with two equal values, a repeat with a different value, a repeated shorthand mention, a repeated field in a struct-like enum variant, a repeat alongside functional update syntax, and a field named three times, which drew the error twice. It did not fire for the same field bound twice in a pattern, which drew E0025, for a field declared twice in the struct definition, which drew E0124, for a missing field, which drew E0063, for an unknown field, which drew E0560, or for a .. base placed before a field, which drew an uncoded error. The same names compiled and ran when a named field was paired with a .. base that filled the rest, when shorthand was used once, when two different structs each had a field of the same name, and when an enum variant literal named each field once. The repairs that ran were removing the duplicate mention, keeping the intended value, and setting the field once in the literal with the later value assigned after construction.

Checklist

  • One literal names each field once - equal values, shorthand, and a .. base do not excuse a repeat.
  • A field named three times draws the error twice; count errors against first uses before assuming two fields are involved.
  • Check the code to find the braces: E0062 for a construction, E0025 for a pattern, E0124 for the struct definition, E0063 for a missing field, E0560 for an unknown one.
  • Repair by removing the duplicate mention, or by setting the field once and assigning the later value after construction.
  • Keep the .. base last in the literal; it fills the fields the literal does not name, and a named field overrides it.
  • Leave legal same-name shapes alone: the same field name on different structs, shorthand used once, and one binding per field in a pattern.

Sources

Keep Exploring