]> git.proxmox.com Git - rustc.git/blob - src/test/ui/consts/miri_unleashed/mutable_references.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / test / ui / consts / miri_unleashed / mutable_references.rs
1 // compile-flags: -Zunleash-the-miri-inside-of-you
2 #![feature(const_mut_refs)]
3 #![allow(const_err)]
4
5 use std::cell::UnsafeCell;
6
7 // a test demonstrating what things we could allow with a smarter const qualification
8
9 // this is fine because is not possible to mutate through an immutable reference.
10 static FOO: &&mut u32 = &&mut 42;
11
12 // this is fine because accessing an immutable static `BAR` is equivalent to accessing `*&BAR`
13 // which puts the mutable reference behind an immutable one.
14 static BAR: &mut () = &mut ();
15
16 struct Foo<T>(T);
17
18 // this is fine for the same reason as `BAR`.
19 static BOO: &mut Foo<()> = &mut Foo(());
20
21 struct Meh {
22 x: &'static UnsafeCell<i32>,
23 }
24
25 unsafe impl Sync for Meh {}
26
27 static MEH: Meh = Meh {
28 x: &UnsafeCell::new(42),
29 //~^ WARN: skipping const checks
30 };
31
32 // this is fine for the same reason as `BAR`.
33 static OH_YES: &mut i32 = &mut 42;
34
35 fn main() {
36 unsafe {
37 *MEH.x.get() = 99;
38 }
39 *OH_YES = 99; //~ ERROR cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
40 }