Closed
Description
Following this small example:
#[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);
}
}
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.
Metadata
Metadata
Assignees
Labels
No labels