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

E0485: Raw requires place

CodeCategoryStability
E0485Struct and enumPermanent

Explanation

@raw and @raw_mut form pointers to existing storage, so their operand must be an addressable place such as a local variable, field, or array element. Literals, arithmetic expressions, and call results are temporary values rather than places and cannot supply a stable address. Raw-pointer operations must also appear in a checked block.

Likely cause

Code applies @raw or @raw_mut directly to a computed value. Store the value in a local first and take that place's address inside checked, or point at an existing field or array element whose lifetime covers the pointer use.

Examples

Take the address of a temporary value

fn main() -> i32 {
    let pointer: ptr const i32 = checked { @raw(40 + 2) };
    checked { @ptr_read(pointer) }
}

Take the address of a local place

fn main() -> i32 {
    let value: i32 = 42;
    let pointer: ptr const i32 = checked { @raw(value) };
    checked { @ptr_read(pointer) }
}

References