E5001
E5001 — Unsafe function call outside unsafe block
What the compiler reports
E5001{{.*}}'reads'
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
//
// An `unsafe fn` states a contract its caller must discharge, so a call needs an unsafe
// context. Calling one from a safe function is the error the declaration exists to produce.
unsafe fn reads(ptr : *mut i32) -> i32 {
let mut v = 0;
unsafe { v = *ptr; }
return v;
}
fn calls(ptr : *mut i32) -> i32 {
return reads(ptr);
}
fn main() -> i32 {
return 0;
}
From tests/frontend/fail/unsafe_fn_called_outside_unsafe.vx, which asserts this diagnostic on every commit.