Sorry I didn't make this very clear, but the implementation of T1 actually depends on B being Fn(S1<'a>) -> A where A shares a lifetime with the parameter. That is, I need to call B as a closure in the implementation, which means the bounds on B have to be in the header of the impl block.
A not pretty hack. (Unsure of practicality.) If I understand correctly you need the the first generic to be higher-kind rather than of concrete lifetime.
trait T1<H> {}
trait T2 {}
struct S1<'a>(&'a u32); // any type with a lifetime
trait Lo<'a> {
type A: 'a + T2;
}
trait Hi: for<'a> Lo<'a> {}
impl<H, B> T1<H> for B where
H: Hi,
B: for<'a> Fn(S1<'a>) -> <H as Lo<'a>>::A {}
Tide currently implements Middleware on all functions Fn(Context<State>, Next<'a, State>) -> BoxFuture<'a, Response>, but I'm trying to implement it for Fn(Context<State>, Next<'a, State>) -> impl Future<Response> + 'a (async functions), and now I'm beginning to see why they didn't.
Thanks for your help anyways; I should've known that they put enough thought into it to realize it was impossible.
trait T1 {}
trait T2 {}
struct S1<'a>(&'a u32); // any type with a lifetime
trait Lo<'a> {
type A: 'a + T2;
}
impl<B> T1 for B where
B: for<'a> Lo<'a> + Fn(S1<'a>) -> <B as Lo<'a>>::A {}
Trying to implement Lo<'a> for all B creates an odd compiler error.
trait T1 {}
trait T2 {}
struct S1<'a>(&'a u32); // any type with a lifetime
trait Lo<'a> {
type A: 'a + T2;
}
impl<'a, B, F> Lo<'a> for B where B: Fn(S1<'a>) -> F, F: 'a + T2 {
type A = F;
}
impl<B> T1 for B where for<'a> B: Lo<'a> + Fn(S1<'a>) -> <B as Lo<'a>>::A {}
error[E0275]: overflow evaluating the requirement `B: Lo<'_>`
--> src/main.rs:17:9
|
17 | impl<B> T1 for B where for<'a> B: Lo<'a> + Fn(S1<'a>) -> <B as Lo<'a>>::A {}
| ^^
|
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate
= note: required because of the requirements on the impl of `Lo<'_>` for `B`
... same thing over and over again
= note: required because of the requirements on the impl of `T1` for `B`