I tried this code (playground):
static mut FLAG: bool = false;
fn main() {
let p = std::ptr::addr_of!(FLAG);
println!("{p:p}")
}
I expected this to compile without adding an unsafe block, since the act of getting the address of the static on its own cannot(?) cause Undefined Behavior. Making addr_of! and addr_of_mut! safe when used on a static mut would make the behavior consistent with UnsafeCell::get, which has identical safety concerns in a multithreaded environment.
Meta
Exists on stable and the nightly version used by playground (2024-05-30).