]> git.lizzy.rs Git - rust.git/blob - tests/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.rs
Rollup merge of #106244 - atouchet:readme3, r=workingjubilee
[rust.git] / tests / ui / unboxed-closures / unboxed-closures-wrong-arg-type-extern-fn.rs
1 // Tests that unsafe extern fn pointers do not implement any Fn traits.
2
3 use std::ops::{Fn, FnMut, FnOnce};
4
5 unsafe fn square(x: isize) -> isize {
6     x * x
7 }
8 // note: argument type here is `isize`, not `&isize`
9
10 fn call_it<F: Fn(&isize) -> isize>(_: &F, _: isize) -> isize {
11     0
12 }
13 fn call_it_mut<F: FnMut(&isize) -> isize>(_: &mut F, _: isize) -> isize {
14     0
15 }
16 fn call_it_once<F: FnOnce(&isize) -> isize>(_: F, _: isize) -> isize {
17     0
18 }
19
20 fn a() {
21     let x = call_it(&square, 22);
22     //~^ ERROR E0277
23 }
24
25 fn b() {
26     let y = call_it_mut(&mut square, 22);
27     //~^ ERROR E0277
28 }
29
30 fn c() {
31     let z = call_it_once(square, 22);
32     //~^ ERROR E0277
33 }
34
35 fn main() {}