static
containing UnsafeCell
can circumvent const-checking with certain feature gates #77353
Open
Description
The following example passes the static const checks, reaching const-eval and erroring post-monomorphization. I need to figure out what's going wrong here before const_mut_refs
is stabilized.
cc #57349
#![feature(const_raw_ptr_deref, const_mut_refs)]
#![allow(unused)]
use std::cell::UnsafeCell;
struct Foo(UnsafeCell<u32>);
unsafe impl Send for Foo {}
unsafe impl Sync for Foo {}
static FOO: Foo = Foo(UnsafeCell::new(42));
static BAR: () = unsafe {
*FOO.0.get() = 5; //~ ERROR
};
fn main() {}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0080]: could not evaluate static initializer
--> src/main.rs:14:5
|
14 | *FOO.0.get() = 5; //~ ERROR
| ^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer
error: aborting due to previous error
For more information about this error, try `rustc --explain E0080`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
Activity