summaryrefslogtreecommitdiffstats
path: root/tests/ui/const-ptr/out_of_bounds_read.rs
blob: a371aa93c5ee2a61d8725eb2ddf0ffac074e5c58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
// error-pattern: evaluation of constant value failed

fn main() {
    use std::ptr;

    const DATA: [u32; 1] = [42];

    const PAST_END_PTR: *const u32 = unsafe { DATA.as_ptr().add(1) };

    const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) };
    const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() };
    const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() };
}