about summary refs log tree commit diff
path: root/tests/ui/static/raw-ref-deref-without-unsafe.rs
blob: 97d08c815bf93155fd496f1c3243b610c14461c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use std::ptr;

static mut BYTE: u8 = 0;
static mut BYTE_PTR: *mut u8 = ptr::addr_of_mut!(BYTE);

// This code should remain unsafe because reading from a static mut is *always* unsafe.

// An unsafe static's ident is a place expression in its own right, so despite the above being safe
// (it's fine to create raw refs to places!) the following derefs the ptr before creating its ref!
static mut DEREF_BYTE_PTR: *mut u8 = ptr::addr_of_mut!(*BYTE_PTR);
//~^ ERROR: use of mutable static

fn main() {
    let _ = unsafe { DEREF_BYTE_PTR };
}