Description
The lifetime elision rules for functions are willing to fail sometimes, and that's good because -> &i32
defaulting to -> &'static i32
would not be what people generally want, and having the error say "hey, what lifetime did you mean?" is way better than getting borrowck errors about "that's not 'static
".
It might be worth taking inspiration from that to improve the elision rules for dyn Trait
, as lints for now and possibly as hard changes in a future edition.
For example, impl dyn Trait
is currently impl dyn Trait + 'static
, but it's not clear that's good. It might be better to require that the user write impl dyn Trait + '_
or impl dyn Trait + 'static
to say which they want. Inspired by this thread: https://users.rust-lang.org/t/why-do-associated-functions-in-impl-dyn-trait-require-static-lifetime/67548/2?u=scottmcm
Similarly, the + 'static
default applies even inside a struct with a lifetime. For example, #91292 had
pub struct SectionMut<'a> {
data: &'a mut Option<Box<dyn SectionData>>,
}
where the implicit + 'static
is more restrictive than needed because it's behind the &'a
-- but being in the Box
hides that from elision.
I don't have any concrete proposal here right now, but I figured I'd open this as a place to track it.
Other examples (feel free to edit this post to add more down here):
Metadata
Metadata
Assignees
Labels
Type
Projects
Status