Open
Description
Code
pub trait MyFn: Fn() -> () {}
fn do_f(f: &dyn MyFn) {}
fn main() {
let f = || {};
do_f(&f);
}
Current output
Jamess-MacBook-Pro:benchground jlogan$ cargo build
Compiling benchground v0.1.0 (/Users/jlogan/git/benchground/benchground)
error[E0277]: the trait bound `[closure@src/fn_bound_repro.rs:6:13: 6:15]: MyFn` is not satisfied
--> src/fn_bound_repro.rs:7:10
|
7 | do_f(&f);
| ^^ the trait `MyFn` is not implemented for closure `[closure@src/fn_bound_repro.rs:6:13: 6:15]`
|
= note: required for the cast from `&[closure@src/fn_bound_repro.rs:6:13: 6:15]` to `&dyn MyFn<Output = ()>`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `benchground` (lib) due to previous error
Jamess-MacBook-Pro:benchground jlogan$
Desired output
Some explanation of what part doesn't match or how a person might implement their intent would be helpful
Rationale and extra context
No response
Other cases
The error emitted is nearly the same regardless of the types of arguments in the trait and in the closure, but when the arguments are references, the error also lists separate lifetimes for each input, which makes it look like lifetimes are the issue - but it seems that they're not, since the issue persists even with no relevant lifetimes involved
Anything else?
No response