]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/validity/cast_fn_ptr1.rs
Auto merge of #103020 - lyming2007:issue-102598-fix, r=jackh726
[rust.git] / src / tools / miri / tests / fail / validity / cast_fn_ptr1.rs
1 //@compile-flags: -Zmiri-permissive-provenance
2
3 fn main() {
4     // Cast a function pointer such that on a call, the argument 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(_x: &i32) {}
8
9     let g: fn(*const i32) = unsafe { std::mem::transmute(f as fn(&i32)) };
10
11     g(0usize as *const i32)
12     //~^ ERROR: encountered a null reference
13 }