I'm trying to use Generic Associated Types in structure that derive serde::Deserialize
.
trait Trait {
type Gat<'a>;
}
struct Foo;
impl Trait for Foo {
type Gat<'a> = &'a str;
}
struct Goo;
impl Trait for Goo {
type Gat<'a> = String;
}
#[derive(serde::Deserialize)]
struct A<'a> {
x: <Foo as Trait>::Gat<'a>, // lifetime may not live long enough consider adding the following bound: `'de: 'a`
y: <Goo as Trait>::Gat<'a>, // this one is OK
}
#[derive(serde::Deserialize)]
struct B<'a> {
x: &'a str, // no problem when inlined
}
The field A::x
got an error :
lifetime may not live long enough consider adding the following bound: `'de: 'a`
but A::y
which type doesn't use the lifetime and B::x
which is "inlined" have no error.
Is the problem from GAT or serde
?