2019-09-29 18:22:18 -05:00
|
|
|
// run-pass
|
|
|
|
#![feature(const_extern_fn)]
|
|
|
|
|
2020-09-01 16:28:11 -05:00
|
|
|
const extern "C" fn foo1(val: u8) -> u8 {
|
2019-09-29 18:22:18 -05:00
|
|
|
val + 1
|
|
|
|
}
|
|
|
|
|
|
|
|
const extern "C" fn foo2(val: u8) -> u8 {
|
|
|
|
val + 1
|
|
|
|
}
|
|
|
|
|
2020-09-01 16:28:11 -05:00
|
|
|
const unsafe extern "C" fn bar1(val: bool) -> bool {
|
2019-09-29 18:22:18 -05:00
|
|
|
!val
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsafe extern "C" fn bar2(val: bool) -> bool {
|
|
|
|
!val
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let a: [u8; foo1(25) as usize] = [0; 26];
|
|
|
|
let b: [u8; foo2(25) as usize] = [0; 26];
|
|
|
|
assert_eq!(a, b);
|
|
|
|
|
|
|
|
let bar1_res = unsafe { bar1(false) };
|
|
|
|
let bar2_res = unsafe { bar2(false) };
|
|
|
|
assert!(bar1_res);
|
|
|
|
assert_eq!(bar1_res, bar2_res);
|
|
|
|
|
2020-09-01 16:28:11 -05:00
|
|
|
let _foo1_cast: extern "C" fn(u8) -> u8 = foo1;
|
|
|
|
let _foo2_cast: extern "C" fn(u8) -> u8 = foo2;
|
|
|
|
let _bar1_cast: unsafe extern "C" fn(bool) -> bool = bar1;
|
|
|
|
let _bar2_cast: unsafe extern "C" fn(bool) -> bool = bar2;
|
2019-09-29 18:22:18 -05:00
|
|
|
}
|