-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
T-typesRelevant 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.needs-rfcThis 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.
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`.
jyn514
Metadata
Metadata
Assignees
Labels
T-typesRelevant 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.needs-rfcThis 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.