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
{{ message }}
Repository navigation
Rust is eagerly evaluating range causing inconsistencies #72763
#[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);
}
}
Nothing in Rust is lazily evaluated. Evaluation order of language constructs like for and the range syntax is in scope of https://github.com/rust-lang/reference/.
Activity
jonas-schievink commentedon May 30, 2020
Nothing in Rust is lazily evaluated. Evaluation order of language constructs like
forand the range syntax is in scope of https://github.com/rust-lang/reference/.eloraiby commentedon May 30, 2020
@jonas-schievink you failed to provide where in that reference! - if it's in there -
jonas-schievink commentedon May 30, 2020
It isn't documented yet – but this is being tracked in rust-lang/reference#248
eloraiby commentedon May 30, 2020
thanks @jonas-schievink