Now that GATs are close to stabilizing, HRTBs are going to be used much more for associated type bounds:
trait Foo {
type Output<'a>;
fn foo(&self) -> Self::Output<'_>;
}
fn foo<F>(foo: F)
where
F: Foo,
for<'a> F::Output<'a>: Clone,
{
// ...
}
What if the elided lifetime could be used as a simpler version of this?
fn foo<F>(foo: F)
where
F: Foo,
F::Output<'_>: Clone,
{
// ...
}
This could also interact nicely with feature(associated_type_bounds)
:
fn foo<F>(foo: F)
where
F: Foo<Output<'_>: Clone>,
{
// ...
}
We'll also need some way to express HRTB bounds with type parameters:
trait Foo {
type Output<T>;
fn foo<T>(self) -> Self::Output<T>;
}
fn foo<F>(foo: F)
where
F: Foo,
for<T: Clone> F::Output<T>: Clone // <---
{
// ...
}
And perhaps _
could be used here as well as sugar, applying the bound on the associated type to the elided generic parameter as default behavior:
fn foo<F>(foo: F)
where
F: Foo,
F::Output<_>: Clone
// => for<T: Clone> F::Output<T>: Clone
{
// ...
}
Again, would work well with feature(associated_type_bounds)
:
fn foo<F>(foo: F)
where
F: Foo<Output<_>: Clone>,
{
// ...
}
Note that neither '_
or _
are allowed in the proposed position, so this would be a non-breaking change.
This idea originally came out of thinking about async function syntax.