Skip to main content

E0021: Field Access on Non-Struct

You tried to access a field on a value that isn't a struct.

Example

fn main() {
let x = 42;
let y = x.value; // Error: cannot access fields on value of type `i64`
}

How to fix

Only access fields on struct values:

struct Point {
x: i64,
y: i64,
}

fn main() {
let p = Point { x: 1, y: 2 };
let y = p.y; // OK
}