E5002
E5002 — Unsafe memory operation outside unsafe block
What the compiler reports
E5002{{.*}}Dereferencing a raw pointer requires an unsafe block
The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.
A program that triggers it
//
// Rust 2024: the body of an `unsafe fn` is not itself an unsafe context. The declaration states
// a contract on the caller; an unsafe operation inside the body still marks itself.
unsafe fn reads(ptr : *mut i32) -> i32 {
let v = *ptr;
return v;
}
fn main() -> i32 {
return 0;
}
From tests/frontend/fail/unsafe_fn_body_is_not_an_unsafe_context.vx, which asserts this diagnostic on every commit.