Open
Description
If the line after this does not work
is commented out, the remaining code does compile.
If there is any other reason why the const
can’t work, while the function can, then the error message is misleading.
struct SomethingStatic<T: 'static>(T);
trait Foo<'a> {
// this does work
const FUN: fn(&&'a ());
}
trait Bar<T /* <- not 'static */> {
// this does work
const FUN: fn(&T);
}
trait Qux<'a> {
// this does work
fn fun() -> SomethingStatic<fn(&&'a ())>;
// only this does not work:
const FUN: SomethingStatic<fn(&&'a ())>;
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0477]: the type `for<'r> fn(&'r &'a ())` does not fulfill the required lifetime
--> src/lib.rs:14:5
|
17 | const FUN: SomethingStatic<fn(&&'a ())>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: type must satisfy the static lifetime
error: aborting due to previous error
For more information about this error, try `rustc --explain E0477`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
Applies to stable as well as the current nightly (1.50.0-nightly (fa4163942 2020-12-14)
)
⟶ originally from this discussion on URLO
@rustbot modify labels: C-bug, T-lang, T-compiler, A-associated-items, A-lifetimes, A-typesystem
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: Lifetimes / regionsArea: Type systemArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)Category: This is a bug.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the language team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.