Description
In #63376, we fixed the behavior of default object lifetime bounds in "binding arguments", as described in this gist. For example the following type;
dyn Foo<Bar = dyn Baz>
will now default dyn Baz
to dyn 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:
trait Foo<'a> {
type Bar: 'a + ?Sized;
}
then dyn Foo<'x, Bar = dyn Baz>
would default to dyn 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 hence where 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.