about summary refs log tree commit diff
path: root/tests/ui/static/reference-to-mut-static-unsafe-fn.rs
blob: d63fd5460d8400d3715a097f5952cae57b0c944c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//@ compile-flags: --edition 2024 -Z unstable-options

fn main() {}

unsafe fn _foo() {
    unsafe {
        static mut X: i32 = 1;
        static mut Y: i32 = 1;

        let _y = &X;
        //~^ ERROR creating a shared reference to a mutable static [E0796]

        let ref _a = X;
        //~^ ERROR creating a shared reference to a mutable static [E0796]

        let ref mut _a = X;
        //~^ ERROR creating a mutable reference to a mutable static [E0796]

        let (_b, _c) = (&X, &mut Y);
        //~^ ERROR creating a shared reference to a mutable static [E0796]
        //~^^ ERROR creating a mutable reference to a mutable static [E0796]

        foo(&X);
        //~^ ERROR creating a shared reference to a mutable static [E0796]
    }
}

fn foo<'a>(_x: &'a i32) {}