points by 0c3ca83 3 days ago | 0 comments
how does that prevent use after free? pretty sure your algorithm is either very poorly explained or doesnt' actually work.
[–] jordan_bonecut 3 days ago
The compiler tracks all of the currently living planes. The compiler tracks from which plane each borrow is borrowed. Once the plane it is borrowed from dies that borrow is no longer valid
[–] 0c3ca83 3 days ago
If you can replace elements in a vector you can make elements unreachable.
[–] jordan_bonecut 3 days ago
[–] 0c3ca83 3 days ago
[–] jordan_bonecut 3 days ago
let x = vec![1, 2, 3]; let a = &mut x[0]; let b = &mut x[1]; swap(a, b);
Because Rust doesn't really know the difference between the whole Vec an element within the vec. Therefore it treats any mutation as one that could potentially invalidate anything with the same lifetime and doesn't compile. So I believe the plane model to be strictly better because it allows for this and still prevents the real scary thing:
let x = vec![1, 2]; let a = &mut x[0]; x.push(3); a = a + 1;
[–] 0c3ca83 3 days ago
[–] jordan_bonecut 3 days ago