In the following snippet, the Filter trait has a lifetime argument in order to allow implementations to use the borrowing lifetime in the Output associated type.
The Assert1 and Assert2 trait are examples of where clauses to use the Scan trait with a Filter In the first case, a named lifetime is available and it compiles just fine.
But the Assert2 trait based on for<'a> bounds fails to build for reasons i do not understand.
struct Foo;
struct FooFilter<'a> {
foo: &'a Foo,
}
trait Filter<'a> {
type Output;
fn make_filter(&'a mut self) -> Self::Output;
}
impl<'a> Filter<'a> for Foo {
type Output = FooFilter<'a>;
fn make_filter(&'a mut self) -> Self::Output {
FooFilter { foo: &*self }
}
}
pub trait Scan<Filter> {}
impl<'a> Scan<FooFilter<'a>> for Foo {}
trait Assert1<'a>
where
Self: Filter<'a>,
Self: Scan<<Self as Filter<'a>>::Output>,
{
}
impl<'a> Assert1<'a> for Foo {}
trait Assert2
where
for<'a> Self: Filter<'a>,
Self: for<'a> Scan<<Self as Filter<'a>>::Output>,
{
}
impl Assert2 for Foo {}