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

E0401: Unknown field

CodeCategoryStability
E0401Struct and enumPermanent

Explanation

A struct literal, struct pattern, field access, or another field-naming operation uses an identifier that is not a field of the relevant struct type.

Likely cause

The field name is misspelled, belongs to a different struct, or the struct definition was changed without updating its construction or use.

Examples

Access an unknown field

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

Use a declared field

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

References