-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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.
Description
Error E0301 "the parameter type T
may not live long enough" could explain where the lifetime requirement comes from.
Here's some example code where the T: 'static
requirement comes implicitly from a Box<Trait>
trait object (so 'static is invisible).
trait Funny { }
fn new_funny_handle<T: Funny + Default>() -> Box<Funny> {
Box::new(T::default())
}
error: the parameter type `T` may not live long enough [--explain E0310]
--> <anon>:5:5
5 |> Box::new(T::default())
|> ^^^^^^^^^^^^^^^^^^^^^^
help: consider adding an explicit lifetime bound `T: 'static`...
note: ...so that the type `T` will meet its required lifetime bounds
--> <anon>:5:5
5 |> Box::new(T::default())
|>
dpzmick, Enet4, flyingmutant, danaugrs, akiross and 1 more
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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.