You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This simple code compiles on current master (0d3bd77) :
fn main() {
let mut vector = vec!(1u, 2u);
for &x in vector.iter() {
let cap = vector.capacity();
println!("Capacity was: {}", cap);
vector.grow(cap, &0u); // be sure to cause reallocation
*vector.get_mut(1u) = 5u;
println!("Value: {}", x);
}
}
and outputs:
Capacity was: 4
Value: 1
Capacity was: 8
Value: 2
while on 0.11 the borrow checker would complain that vector is already immutably borrowed by vector.iter().
It allows me to write 5u in vector[1] and then read it as 2u, because reallocation of the vector caused the iterator's slice to refer to freed memory.
itself.
This breaks code like:
for &x in my_vector.iter() {
my_vector[2] = "wibble";
...
}
Change this code to not invalidate iterators. For example:
for i in range(0, my_vector.len()) {
my_vector[2] = "wibble";
...
}
The `for-loop-does-not-borrow-iterators` test for rust-lang#8372 was incorrect
and has been removed.
Closesrust-lang#16820.
[breaking-change]
This simple code compiles on current master (0d3bd77) :
and outputs:
while on 0.11 the borrow checker would complain that
vector
is already immutably borrowed byvector.iter()
.It allows me to write
5u
invector[1]
and then read it as2u
, because reallocation of the vector caused the iterator's slice to refer to freed memory.(was found in a StackOverflow question : http://stackoverflow.com/q/25528271/2536143 )
The text was updated successfully, but these errors were encountered: