-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-type-systemArea: Type systemArea: Type systemA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-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.
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
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-type-systemArea: Type systemArea: Type systemA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-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.