2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2017-06-18 18:57:39 +03:00
|
|
|
use std::mem;
|
|
|
|
|
2017-02-24 00:32:21 +01:00
|
|
|
const FOO: fn(u8) -> u8 = |v: u8| { v };
|
2017-02-22 01:24:16 +01: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 01:56:57 -04:00
|
|
|
fn func_specific() -> fn() -> u32 {
|
2017-02-22 01:24:16 +01:00
|
|
|
|| return 42
|
|
|
|
}
|
|
|
|
|
2017-06-18 18:57:39 +03:00
|
|
|
fn generic<T>(_: T) -> fn() -> usize {
|
|
|
|
|| mem::size_of::<T>()
|
|
|
|
}
|
|
|
|
|
2017-02-22 01:24:16 +01:00
|
|
|
fn main() {
|
|
|
|
// Items
|
|
|
|
assert_eq!(func_specific()(), 42);
|
2017-02-24 00:32:21 +01:00
|
|
|
let foo: fn(u8) -> u8 = |v: u8| { v };
|
2017-02-22 01:24:16 +01:00
|
|
|
assert_eq!(foo(31), 31);
|
|
|
|
// Constants
|
|
|
|
assert_eq!(FOO(31), 31);
|
2017-02-24 00:32:21 +01: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 18:57:39 +03:00
|
|
|
assert_eq!(generic(0i8)(), 1);
|
2017-02-22 01:24:16 +01:00
|
|
|
}
|