]> git.proxmox.com Git - rustc.git/blob - tests/ui/consts/const-extern-fn/const-extern-fn.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / consts / const-extern-fn / const-extern-fn.rs
1 // run-pass
2 #![feature(const_extern_fn)]
3
4 const extern "C" fn foo1(val: u8) -> u8 {
5 val + 1
6 }
7
8 const extern "C" fn foo2(val: u8) -> u8 {
9 val + 1
10 }
11
12 const unsafe extern "C" fn bar1(val: bool) -> bool {
13 !val
14 }
15
16 const unsafe extern "C" fn bar2(val: bool) -> bool {
17 !val
18 }
19
20
21 fn main() {
22 let a: [u8; foo1(25) as usize] = [0; 26];
23 let b: [u8; foo2(25) as usize] = [0; 26];
24 assert_eq!(a, b);
25
26 let bar1_res = unsafe { bar1(false) };
27 let bar2_res = unsafe { bar2(false) };
28 assert!(bar1_res);
29 assert_eq!(bar1_res, bar2_res);
30
31 let _foo1_cast: extern "C" fn(u8) -> u8 = foo1;
32 let _foo2_cast: extern "C" fn(u8) -> u8 = foo2;
33 let _bar1_cast: unsafe extern "C" fn(bool) -> bool = bar1;
34 let _bar2_cast: unsafe extern "C" fn(bool) -> bool = bar2;
35 }