struct A<'a> {
a: &'a &'a mut [&'a u32]
}
fn a(a: A) {
b(&a)
}
fn b<'a>(_: &'a A<'a>) {}
The compiler will complain:
`a` does not live long enough
I understand since &'a u32
is behind a &mut [&'a u32]
, 'a
becomes invariant. However in this case &mut [&'a u32]
is behind a shared reference, which prevents it from being mutated. So struct A
is really
struct A<'a> {
a: &'a &'a [&'a u32]
}
and with the above definition, function a
and b
compiles.
Can we make 'a
covariant in this case?