]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/validity/cast_fn_ptr2.rs
Auto merge of #103020 - lyming2007:issue-102598-fix, r=jackh726
[rust.git] / src / tools / miri / tests / fail / validity / cast_fn_ptr2.rs
1 //@compile-flags: -Zmiri-permissive-provenance
2
3 fn main() {
4     // Cast a function pointer such that when returning, the return value gets transmuted
5     // from raw ptr to reference. This is ABI-compatible, so it's not the call that
6     // should fail, but validation should.
7     fn f() -> *const i32 {
8         0usize as *const i32
9     }
10
11     let g: fn() -> &'static i32 = unsafe { std::mem::transmute(f as fn() -> *const i32) };
12
13     let _x = g();
14     //~^ ERROR: encountered a null reference
15 }