2020-12-01 08:42:22 -06:00
|
|
|
//@ run-pass
|
2020-12-01 04:09:25 -06:00
|
|
|
#![feature(core_intrinsics)]
|
|
|
|
#![feature(const_heap)]
|
|
|
|
use std::intrinsics;
|
|
|
|
|
2020-12-01 08:42:22 -06:00
|
|
|
const FOO: &i32 = foo();
|
2023-12-16 09:24:25 -06:00
|
|
|
const FOO_RAW: *const i32 = foo();
|
2020-12-01 04:09:25 -06:00
|
|
|
|
|
|
|
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() {
|
2023-12-16 09:24:25 -06:00
|
|
|
assert_eq!(*FOO, 20);
|
|
|
|
assert_eq!(unsafe { *FOO_RAW }, 20);
|
2020-12-01 04:09:25 -06:00
|
|
|
}
|