I suspect this is about Bar not being covariant over 'a, so that &'short F::Bar<'long> can't be coerced to &'short F::Bar<'short>.
Is that correct? If so, is there a way to force Bar to be covariant over its lifetime?
trait Foo: 'static {
type Bar<'a>;
fn as_bar(&self) -> Self::Bar<'_>;
}
fn foo<F: Foo>(foo: F) {
let bar = foo.as_bar();
handle_bar::<F>(&bar);
}
fn handle_bar<'a, F: Foo>(_: &'a F::Bar<'a>) {}
let bar = foo.as_bar();
--- binding `bar` declared here
handle_bar::<F>(&bar);
^^^^ borrowed value does not live long enough
}
-
|
`bar` dropped here while still borrowed
borrow might be used here, when `bar` is dropped and runs the destructor for type `<F as Foo>::Bar<'_>`