I reduced my problem to this minimum reproducible example (playground):
use std::marker::PhantomData;
pub trait D<'a> {
type A: A + 'a;
type B: B + 'a;
}
pub trait A {
fn a(self);
}
pub trait B {
fn b(self);
}
pub struct AA {}
impl A for AA {
fn a() {}
}
pub struct BB<'a> {
phantom: PhantomData<&'a u8>,
}
impl<'a> B for BB<'a> {
fn b() {}
}
impl<'a: 'd, 'd> D<'d> for E<'a> {
type A = AA;
type B = BB<'a>;
}
#[derive(Clone)]
pub struct E<'a> {
phantom: PhantomData<&'a u8>,
}
pub struct S<D_T>
where
D_T: for<'d> D<'d>,
{
a: D_T,
}
pub enum R<'a> {
RR(S<E<'a>>),
}
I'm getting
error: implementation of `D` is not general enough
--> src/lib.rs:48:8
|
3 | / pub trait D<'a> {
4 | | type A: A + 'a;
5 | | type B: B + 'a;
6 | | }
| |_- trait `D` defined here
...
48 | RR(S<E<'a>>),
| ^^^^^^^^ implementation of `D` is not general enough
|
= note: `D<'0>` would have to be implemented for the type `E<'a>`, for any lifetime `'0`...
= note: ...but `D<'_>` is actually implemented for the type `E<'1>`, for some specific lifetime `'1`
I have a small idea why it's happening, but is there a way to have BB with a reference in this case? Most of the things here are from a library I don't control so I cannot change them.