The implied deref to statics introduced by HIR->THIR lowering is only
used to create place expressions, it lacks unsafe semantics.
It is also confusing, as there is no visible `*ident` in the source.
For both classes of "unsafe static" (extern static and static mut)
allow this operation.
We lack a clear story around `thread_local! { static mut }`, which
is actually its own category of item that reuses the static syntax but
has its own rules. It's possible they should be similarly included, but
in the absence of a good reason one way or another, we do not bless it.
17 lines
544 B
Rust
17 lines
544 B
Rust
//@ check-pass
|
|
#![feature(raw_ref_op)]
|
|
use std::ptr;
|
|
|
|
// see https://github.com/rust-lang/rust/issues/125833
|
|
// notionally, taking the address of a static mut is a safe operation,
|
|
// as we only point at it instead of generating a true reference to it
|
|
static mut NOWHERE: usize = 0;
|
|
|
|
fn main() {
|
|
let p2nowhere = ptr::addr_of!(NOWHERE);
|
|
let p2nowhere = ptr::addr_of_mut!(NOWHERE);
|
|
|
|
// testing both addr_of and the expression it directly expands to
|
|
let raw2nowhere = &raw const NOWHERE;
|
|
let raw2nowhere = &raw mut NOWHERE;
|
|
}
|