struct Manager<'a> {
text: &'a str,
}
struct List<'a> {
manager: Manager<'a>,
}
impl<'a> List<'a> {
pub fn xxx(self: &'a mut List<'a>) {}
pub fn yyy<'b>(self: &'b mut List<'a>) {}
}
fn main() {
let mut list = List {
manager: Manager { text: "hello" }
};
list.xxx(); // Produced one &'a mut list<'a >
list.text = 20; // error
}
This code produce a permanent borrow &'a mut List<'a>
, and the list
can no longer be accessed.
My question is: does this mutable borrow &'a mut List<'a>
actually last as long as the lifetime of list
, or has this mutable borrow &'a mut List<'a>
already been released, but the borrow checker notices that the lifetime annotation of the mutable borrow is the same as 'a
, so the borrow checker rejects the code?