E0401: Unknown field
| Code | Category | Stability |
|---|---|---|
E0401 | Struct and enum | Permanent |
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
}