rust/tests/ui/consts/const-eval/heap/alloc_intrinsic_nontransient.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

20 lines
352 B
Rust
Raw Normal View History

2020-12-01 20:12:22 +05:30
// run-pass
2020-12-01 15:39:25 +05:30
#![feature(core_intrinsics)]
#![feature(const_heap)]
#![feature(const_mut_refs)]
use std::intrinsics;
2020-12-01 20:12:22 +05:30
const FOO: &i32 = foo();
2020-12-01 15:39:25 +05:30
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() {
2020-12-01 20:12:22 +05:30
assert_eq!(*FOO, 20)
2020-12-01 15:39:25 +05:30
}