2015-08-12 19:56:27 +00:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
2015-08-13 13:36:31 +00:00
|
|
|
#[deny(needless_range_loop, explicit_iter_loop)]
|
2015-08-12 19:56:27 +00:00
|
|
|
fn main() {
|
2015-08-13 13:36:31 +00:00
|
|
|
let mut vec = vec![1, 2, 3, 4];
|
2015-08-12 19:56:27 +00:00
|
|
|
let vec2 = vec![1, 2, 3, 4];
|
|
|
|
for i in 0..vec.len() { //~ERROR the loop variable `i` is only used to index `vec`.
|
|
|
|
println!("{}", vec[i]);
|
|
|
|
}
|
|
|
|
for i in 0..vec.len() { //~ERROR the loop variable `i` is used to index `vec`.
|
|
|
|
println!("{} {}", vec[i], i);
|
|
|
|
}
|
|
|
|
for i in 0..vec.len() { // not an error, indexing more than one variable
|
|
|
|
println!("{} {}", vec[i], vec2[i]);
|
|
|
|
}
|
2015-08-13 13:36:31 +00:00
|
|
|
|
|
|
|
for _v in vec.iter() { } //~ERROR it is more idiomatic to loop over `&vec`
|
|
|
|
for _v in vec.iter_mut() { } //~ERROR it is more idiomatic to loop over `&mut vec`
|
|
|
|
|
|
|
|
for _v in &vec { } // these are fine
|
|
|
|
for _v in &mut vec { } // these are fine
|
2015-08-12 19:56:27 +00:00
|
|
|
}
|