2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2017-06-18 10:57:39 -05:00
|
|
|
use std::mem;
|
|
|
|
|
2017-02-23 17:32:21 -06:00
|
|
|
const FOO: fn(u8) -> u8 = |v: u8| { v };
|
2017-02-21 18:24:16 -06:00
|
|
|
|
|
|
|
const BAR: [fn(&mut u32); 5] = [
|
|
|
|
|_: &mut u32| {},
|
|
|
|
|v: &mut u32| *v += 1,
|
|
|
|
|v: &mut u32| *v += 2,
|
|
|
|
|v: &mut u32| *v += 3,
|
|
|
|
|v: &mut u32| *v += 4,
|
|
|
|
];
|
2019-10-04 00:56:57 -05:00
|
|
|
fn func_specific() -> fn() -> u32 {
|
2017-02-21 18:24:16 -06:00
|
|
|
|| return 42
|
|
|
|
}
|
|
|
|
|
2017-06-18 10:57:39 -05:00
|
|
|
fn generic<T>(_: T) -> fn() -> usize {
|
|
|
|
|| mem::size_of::<T>()
|
|
|
|
}
|
|
|
|
|
2017-02-21 18:24:16 -06:00
|
|
|
fn main() {
|
|
|
|
// Items
|
|
|
|
assert_eq!(func_specific()(), 42);
|
2017-02-23 17:32:21 -06:00
|
|
|
let foo: fn(u8) -> u8 = |v: u8| { v };
|
2017-02-21 18:24:16 -06:00
|
|
|
assert_eq!(foo(31), 31);
|
|
|
|
// Constants
|
|
|
|
assert_eq!(FOO(31), 31);
|
2017-02-23 17:32:21 -06:00
|
|
|
let mut a: u32 = 0;
|
|
|
|
assert_eq!({ BAR[0](&mut a); a }, 0);
|
|
|
|
assert_eq!({ BAR[1](&mut a); a }, 1);
|
|
|
|
assert_eq!({ BAR[2](&mut a); a }, 3);
|
|
|
|
assert_eq!({ BAR[3](&mut a); a }, 6);
|
|
|
|
assert_eq!({ BAR[4](&mut a); a }, 10);
|
2017-06-18 10:57:39 -05:00
|
|
|
assert_eq!(generic(0i8)(), 1);
|
2017-02-21 18:24:16 -06:00
|
|
|
}
|