Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

E0402: Duplicate field

CodeCategoryStability
E0402Struct and enumPermanent

Explanation

A struct declaration defines the same field name more than once, a struct literal supplies more than one initializer for the same field, or a struct pattern names the same field twice.

Likely cause

A field declaration, initializer, or pattern field was duplicated, possibly after a rename or copy-and-paste edit. Give every declared field a unique name, and name each field at most once in a struct literal or pattern.

Examples

Repeated field initializer

struct Point { x: i32, y: i32 }
fn main() -> i32 {
    let point = Point { x: 10, x: 20, y: 32 };
    point.y
}

Initialize each field once

struct Point { x: i32, y: i32 }
fn main() -> i32 {
    let point = Point { x: 10, y: 32 };
    point.x + point.y
}

References