Sure a reference that outlives its holder is possible with mutable references too. An example with Option<&'a mut i32>
as the field is simplest, because then the reference can be given away by ownership semantics (Option::take
method).
You're right that borrowing rules do differ between mutable and shared references, I was trying to find where I had just written a comment about that. (Searching, ok I found it.) Here is that comment Returning iterators and lifetime annotation woes - #5 by bluss
To understand that comment for this case, remember that the method takes &self
. That's the outermost layer of references. The inner one is the struct field self.x
.