object lifetime bound defaults in trait bindings are incompletely implemented #63618
Labels
A-lifetimes
Area: Lifetimes / regions
A-trait-objects
Area: trait objects, vtable layout
A-trait-system
Area: Trait system
A-type-system
Area: Type system
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
In #63376, we fixed the behavior of default object lifetime bounds in "binding arguments", as described in this gist. For example the following type;
will now default
dyn Baz
todyn Baz + 'static
.However, the rules were incompletely implemented. If the trait has a lifetime parameter, we currently require an explicit lifetime bound. The expected behavior is to use the bounds declared on the associated type to set the default. So, given
Foo
like so:then
dyn Foo<'x, Bar = dyn Baz>
would default todyn Baz + 'a
. Presently, however, it gives an error.NB. There is one "design decision" to be made; does a where clause like
where Self::Bar: 'x
adjust the default? And how does that work when extended to GATs? My personal opinion is that we should limit ourselves to bounds declared on the associated type itself (and hencewhere Self::Bar: 'x
would not count towards the default object lifetime bound), but this merits a bit of further discussion. This is largely because the complexity to specify and implement the behavior around where clauses and with GATs is kind feels out of proportion with the benefit.The text was updated successfully, but these errors were encountered: