Closed nilehmann closed 4 days ago
Here's a minimal repro
fn test(vec: &mut RVec<RVec<i32>>) {
vec[0] = RVec::new();
}
Here's the issue. Because RVec<T>
is Drop
, the line vec[0] = RVec::new()
is "swapping" the old value with RVec::new()
and dropping the old value. This used to happen as a single mir operation called DropAndReplace
but now it desugars to more than one statement. Something like
1: _2 = vec.index_mut(0)
2: drop(*_2)
3: (*_2) = RVec::new()
Here _2
should have type &mut RVec<i32>
but in between lines 2
and 3
, the reference momentarily points to uninitialized memory, so we are are "breaking" the invariant (i.e., it is a value of type RVec<i32>
) after 2
and then reestablishing it in 3
. This would be fundamentally addressed with folding/unfolding of mutable references, but in this particular case I think we could just ignore drop(*_2)
The following code panic when trying to update
centers[i]
This is the panic