add tests for fn pointers
This commit is contained in:
parent
4d090fa693
commit
9565d48203
2 changed files with 27 additions and 0 deletions
13
tests/compile-fail/deref_fn_ptr.rs
Normal file
13
tests/compile-fail/deref_fn_ptr.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#![feature(custom_attribute)]
|
||||
#![allow(dead_code, unused_attributes)]
|
||||
|
||||
fn f() {}
|
||||
|
||||
#[miri_run]
|
||||
fn deref_fn_ptr() -> i32 {
|
||||
unsafe {
|
||||
*std::mem::transmute::<fn(), *const i32>(f) //~ ERROR: tried to dereference a function pointer
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
14
tests/compile-fail/execute_memory.rs
Normal file
14
tests/compile-fail/execute_memory.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#![feature(custom_attribute, box_syntax)]
|
||||
#![allow(dead_code, unused_attributes)]
|
||||
|
||||
#[miri_run]
|
||||
fn deref_fn_ptr() {
|
||||
//FIXME: this span is wrong
|
||||
let x = box 42; //~ ERROR: tried to treat a memory pointer as a function pointer
|
||||
unsafe {
|
||||
let f = std::mem::transmute::<Box<i32>, fn()>(x);
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue