]> git.proxmox.com Git - rustc.git/blob - src/test/ui/closures/closure_no_cap_coerce_many_run_pass.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / closures / closure_no_cap_coerce_many_run_pass.rs
1 // run-pass
2 // Ensure non-capturing Closure passing CoerceMany work correctly.
3 fn foo(_: usize) -> usize {
4 0
5 }
6
7 fn bar(_: usize) -> usize {
8 1
9 }
10
11 fn add(a: i32, b: i32) -> i32 {
12 a + b
13 }
14
15 fn main() {
16 // Coerce result check
17
18 type FnPointer = fn(usize) -> usize;
19
20 let c = |x| x;
21 let c_pointer: FnPointer = c;
22 assert_eq!(c_pointer(42), 42);
23
24 let f = match 0 {
25 0 => foo,
26 1 => |_| 1,
27 _ => unimplemented!(),
28 };
29 assert_eq!(f(42), 0);
30
31 let f = match 2 {
32 2 => |_| 2,
33 0 => foo,
34 _ => unimplemented!(),
35 };
36 assert_eq!(f(42), 2);
37
38 let f = match 1 {
39 0 => foo,
40 1 => bar,
41 2 => |_| 2,
42 _ => unimplemented!(),
43 };
44 assert_eq!(f(42), 1);
45
46 let clo0 = |_: usize| 0;
47 let clo1 = |_| 1;
48 let clo2 = |_| 2;
49 let f = match 0 {
50 0 => clo0,
51 1 => clo1,
52 2 => clo2,
53 _ => unimplemented!(),
54 };
55 assert_eq!(f(42), 0);
56
57 let funcs = [add, |a, b| (a - b) as i32];
58 assert_eq!([funcs[0](5, 5), funcs[1](5, 5)], [10, 0]);
59 }