Closed safinaskar closed 1 year ago
Also, you say "The resulting struct exhibits the same behaviour we talk about later in this section". Unfortunately, this struct is not invariant. And it seems you rely on it being invariant
Ah thanks, that was a typo — it was meant to have a let mut
in there. I’ve fixed it now.
Unfortunately, this struct is not invariant. And it seems you rely on it being invariant
Right, the struct itself is not invariant. However, the argument still applies because the equivalent of the uwu
function would take a unique reference to the struct, making it invariant in the inner lifetime:
struct SelfRef<'this> {
a: i32,
b: &'this i32,
}
fn main() {
let mut self_ref = SelfRef { a: 37, b: &0 };
uwu(&mut self_ref);
drop(self_ref); // Comment this line to have it compile
}
fn uwu<'a: 'b, 'b>(self_ref: &'a mut SelfRef<'b>) {
self_ref.b = &self_ref.a;
}
Hi. Thanks a lot for post https://sabrinajewson.org/blog/null-lifetime . It contains the following very strange diff:
First two lines are identical, so there is no need to mark them as changed