-
Notifications
You must be signed in to change notification settings - Fork 1.4k
for: replace range() function with range notation #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It looks like this is a fairly new change. I also discovered by wading through various github issues for Rust that the new syntax for basic for loops using numeric ranges is:
|
Also apparently brackets are required in some cases but not in others?
|
I encountered this warning in Rust book, too. Thanks for sharing the information @genbattle |
|
Is there any way to avoid this warning when using a variable in the range? ie let a = [i32; 10];
for i in range(0, a.len()) {} |
fn main() {
let a: [i32; 2] = [1, 2] ;
for i in 0..a.len() {
println!("{:?}", i);
}
} |
I was updating old code of mine and got this warning for one of my code files:
I pulled up Rust by Example to see what the new idiomatic way of doing this was and found that Rust by Example was using the same (apparently unstable) syntax. The Rust book also uses the outdated syntax.
So at the moment there's no straightforward up-to-date resources on what the syntax should be. But apparently it involves Rust's new [a..b] range syntax. Can someone with more knowledge about what the syntax should be please update Rust by Example.
The text was updated successfully, but these errors were encountered: