Open
Description
trait Trait {
fn fun();
}
fn takes_static_fn(_: impl Fn() + 'static) {}
fn test<T: Trait>() {
// these work
takes_static_fn(|| T::fun());
takes_static_fn(T::fun as fn());
// this seems like it ought to work
takes_static_fn(T::fun);
}
error[E0310]: the parameter type `T` may not live long enough
--> src/lib.rs:12:5
|
7 | fn test<T: Trait>() {
| -- help: consider adding an explicit lifetime bound...: `T: 'static +`
...
12 | takes_static_fn(T::fun);
| ^^^^^^^^^^^^^^^ ...so that the type `fn() {<T as Trait>::fun}` will meet its required lifetime bounds
For more information about this error, try `rustc --explain E0310`.