Skip to main content

E0022: Unknown Field Access

You tried to access a field that doesn't exist on the type.

Example

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

fn main() {
let p = Point { x: 1, y: 2 };
let z = p.z; // Error: struct `Point` has no field named `z`
}

How to fix

Use a field that exists on the struct:

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

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

Or add the field to the struct definition if needed.