rust/tests/compile-fail/validity/cast_fn_ptr2.rs

12 lines
467 B
Rust
Raw Normal View History

fn main() {
// Cast a function pointer such that when returning, the return value gets transmuted
2019-02-15 19:43:56 -06:00
// from raw ptr to reference. This is ABI-compatible, so it's not the call that
// should fail, but validation should.
fn f() -> *const i32 { 0usize as *const i32 }
let g: fn() -> &'static i32 = unsafe { std::mem::transmute(f as fn() -> *const i32) };
2019-02-15 19:43:56 -06:00
let _x = g();
//~^ ERROR encountered 0, but expected something greater or equal to 1
}