about summary refs log tree commit diff
path: root/tests/ui/consts/const-eval/heap/ptr_not_made_global.rs
blob: 6980e92c21896688c64866fb1ab4dcbb884b2335 (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
// Ensure that we reject interning `const_allocate`d allocations in the final value of constants
// if they have not been made global through `const_make_global`. The pointers are made *immutable*
// to focus the test on the missing `make_global`; `ptr_not_made_global_mut.rs` covers the case
// where the pointer remains mutable.

#![feature(core_intrinsics)]
#![feature(const_heap)]
use std::intrinsics;

const FOO: &i32 = foo();
//~^ error: encountered `const_allocate` pointer in final value that was not made global
const FOO_RAW: *const i32 = foo();
//~^ error: encountered `const_allocate` pointer in final value that was not made global

const fn foo() -> &'static i32 {
    let t = unsafe {
        let i = intrinsics::const_allocate(4, 4) as *mut i32;
        *i = 20;
        i
    };
    unsafe { &*t }
}

fn main() {}