struct A;
fn y<'r>(a: &'r mut Vec<&'r A>) {}
fn x<'r>(a: &'r mut Vec<&'r A>) {
y(a);
y(a);
}
Compilation of this code fails, saying that *a
cannot be mutably borrowed second time. When I make the signature look like this (a: &'a mut Vec<&A>)
, i.e. remove a lifetime from a reference of Vec
s content, it compiles just fine.
Why the original code cannot be compiled? I'm unable to see an issue here. For me lifetimes on reference to vector and its content mean just that vector and its content live for the same amount of "time". Where am I wrong?