I'm not even totally sure this is exclusively related to GATs, but I haven't found a way to reproduce it w/o them:
trait Slice {
type S<'a>: Copy
where
Self: 'a;
}
struct Foo<'a, L: Slice + 'a> {
foo: L::S<'a>,
}
impl<'a, L: Slice + 'a> Foo<'a, L> {
fn foo(&self) -> L::S<'_> {
self.foo
}
}
I would expect this code to compile but I'm getting a lifetime error in the body of the foo()
function. It still doesn't work even if I annotate the lifetime explicitly:
impl<'a, L: Slice + 'a> Foo<'a, L> {
fn foo<'b>(&'b self) -> L::S<'b>
where
'a: 'b,
{
// 'a lives longer than 'b, so why can't it be coerced down to 'b?
self.foo
}
}
What am I missing?