E0490: Field ptr requires field
| Code | Category | Stability |
|---|---|---|
E0490 | Struct and enum | Permanent |
Explanation
@field_ptr asks the compiler for the address of a field under its chosen struct layout, so its operand must syntactically be a field-access place such as value.field. A whole variable, array element, or computed value does not identify a struct field for this layout-mediated operation.
Likely cause
Code passed a local or another non-field expression to @field_ptr. Select the intended struct field, or use @raw or @raw_mut when the goal is to address a whole place. Raw-pointer intrinsics must appear in a checked block.
Examples
Request a field pointer for a whole value
struct Pair { value: i32 }
fn main() -> i32 {
let pair = Pair { value: 42 };
let pointer = checked { @field_ptr(pair) };
checked { @ptr_read(pointer) }
}
Request a pointer to a named field
struct Pair { value: i32 }
fn main() -> i32 {
let pair = Pair { value: 42 };
let pointer: ptr mut i32 = checked { @field_ptr(pair.value) };
checked { @ptr_read(pointer) }
}