about summary refs log tree commit diff
path: root/tests/ui/consts/const-eval/heap/make-global.rs
blob: b26fe2434ab8b4c8bc196143a09e354d8d8d5290 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//@ run-pass
#![feature(core_intrinsics)]
#![feature(const_heap)]
use std::intrinsics;

const FOO: &i32 = foo();
const FOO_RAW: *const i32 = foo();

const fn foo() -> &'static i32 {
    unsafe {
        let ptr = intrinsics::const_allocate(4, 4);
        let t = ptr as *mut i32;
        *t = 20;
        intrinsics::const_make_global(ptr);
        &*t
    }
}
fn main() {
    assert_eq!(*FOO, 20);
    assert_eq!(unsafe { *FOO_RAW }, 20);
}