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
#[cfg(test)]
mod tests {
#[test]
fn test_for() {
let mut v = Vec::new();
for i in 0..10 {
v.push(i);
}
for i in 0..v.len() {
if i < 100 {
v.push(i);
}
}
assert!(v.len() == 110); // Crash! expected 110, count is 20
}
#[test]
fn test_loop() {
let mut v = Vec::new();
for i in 0..10 {
v.push(i);
}
let mut i = 0;
loop {
if i >= v.len() {
break;
}
if i < 100 {
v.push(i);
}
i += 1;
}
assert!(v.len() == 110);
}
}
Following this small example:
If that's the normal behaviour, it should be documented in https://doc.rust-lang.org/std/ops/struct.Range.html, in the language references and tutorials.
The behaviour as it stands is in contrast of what other languages implements and is confusing.
The text was updated successfully, but these errors were encountered: