]> git.lizzy.rs Git - rust.git/blob - tests/run-pass/non_capture_closure_to_fn_ptr.rs
e6a5017847d4d78d04e2f13f56bc5df632be0f39
[rust.git] / tests / run-pass / non_capture_closure_to_fn_ptr.rs
1 // allow(const_err) to work around a bug in warnings
2 #[allow(const_err)]
3 static FOO: fn() = || { assert_ne!(42, 43) };
4 #[allow(const_err)]
5 static BAR: fn(i32, i32) = |a, b| { assert_ne!(a, b) };
6
7 // use to first make the closure FnOnce() before making it fn()
8 fn magic<F: FnOnce()>(f: F) -> F { f }
9
10 fn main() {
11     FOO();
12     BAR(44, 45);
13     let bar: unsafe fn(i32, i32) = BAR;
14     unsafe { bar(46, 47) };
15     let boo: &dyn Fn(i32, i32) = &BAR;
16     boo(48, 49);
17
18     let f = magic(||{}) as fn();
19     f();
20 }