Open
Description
Code
fn call_fn<F: Fn() -> ()>(f: &F) {
f()
}
fn call_any<F: std::any::Any>(f: &F) {
call_fn(f)
}
fn main() {
call_any(&|| {});
}
currently produces on stable
error[E0277]: expected a `std::ops::Fn<()>` closure, found `F`
--> src/main.rs:6:13
|
1 | fn call_fn<F: Fn() -> ()>(f: &F) {
| ------- ---------- required by this bound in `call_fn`
...
6 | call_fn(f)
| ^ expected an `Fn<()>` closure, found `F`
|
= help: the trait `std::ops::Fn<()>` is not implemented for `F`
= note: wrap the `F` in a closure with no arguments: `|| { /* code */ }
= help: consider adding a `where F: std::ops::Fn<()>` bound
note: wrap the F in a closure with no arguments: || { /* code */ }
- ???where F: std::ops::Fn<()>
- incorrectFn
syntax
On nightly situation is more interesting:
error[E0277]: expected a `std::ops::Fn<()>` closure, found `F`
--> src/main.rs:6:13
|
1 | fn call_fn<F: Fn() -> ()>(f: &F) {
| ------- ---------- required by this bound in `call_fn`
...
5 | fn call_any<F: std::any::Any>(f: &F) {
| -- help: consider further restricting this bound: `F: std::ops::Fn<()> +`
6 | call_fn(f)
| ^ expected an `Fn<()>` closure, found `F`
|
= help: the trait `std::ops::Fn<()>` is not implemented for `F`
= note: wrap the `F` in a closure with no arguments: `|| { /* code */ }
-- help: consider further restricting this bound: F: std::ops::Fn<()> +
has missing type and incorrectFn
syntax (Fn()
is correct)