]> git.lizzy.rs Git - rust.git/blob - tests/ui/unboxed-closures/unboxed-closures-extern-fn-hr.rs
Rollup merge of #106856 - vadorovsky:fix-atomic-annotations, r=joshtriplett
[rust.git] / tests / ui / unboxed-closures / unboxed-closures-extern-fn-hr.rs
1 // run-pass
2 // Checks that higher-ranked extern fn pointers implement the full range of Fn traits.
3
4 fn square(x: &isize) -> isize { (*x) * (*x) }
5
6 fn call_it<F:Fn(&isize)->isize>(f: &F, x: isize) -> isize {
7     (*f)(&x)
8 }
9
10 fn call_it_boxed(f: &dyn Fn(&isize) -> isize, x: isize) -> isize {
11     f(&x)
12 }
13
14 fn call_it_mut<F:FnMut(&isize)->isize>(f: &mut F, x: isize) -> isize {
15     (*f)(&x)
16 }
17
18 fn call_it_once<F:FnOnce(&isize)->isize>(f: F, x: isize) -> isize {
19     f(&x)
20 }
21
22 fn main() {
23     let x = call_it(&square, 22);
24     let x1 = call_it_boxed(&square, 22);
25     let y = call_it_mut(&mut square, 22);
26     let z = call_it_once(square, 22);
27     assert_eq!(x, square(&22));
28     assert_eq!(x1, square(&22));
29     assert_eq!(y, square(&22));
30     assert_eq!(z, square(&22));
31 }