rust/tests/run-pass/function_pointers.rs

18 lines
300 B
Rust
Raw Normal View History

2016-06-08 06:43:34 -05:00
fn f() -> i32 {
42
}
fn return_fn_ptr() -> fn() -> i32 {
f
}
fn call_fn_ptr() -> i32 {
return_fn_ptr()()
}
fn main() {
assert_eq!(call_fn_ptr(), 42);
2016-06-20 03:35:15 -05:00
assert!(return_fn_ptr() == f);
assert!(return_fn_ptr() as unsafe fn() -> i32 == f as fn() -> i32 as unsafe fn() -> i32);
}