Open
Description
openedon Oct 8, 2021
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
Relevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.This change is large or controversial enough that it should have an RFC accepted before doing it.This change is large or controversial enough that it should have an RFC accepted before doing it.