2015-08-12 19:56:27 +00:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
2015-08-25 16:26:20 +00:00
|
|
|
use std::collections::*;
|
|
|
|
|
2015-08-17 05:23:57 +00:00
|
|
|
struct Unrelated(Vec<u8>);
|
|
|
|
impl Unrelated {
|
|
|
|
fn next(&self) -> std::slice::Iter<u8> {
|
|
|
|
self.0.iter()
|
|
|
|
}
|
2015-08-25 16:26:20 +00:00
|
|
|
|
|
|
|
fn iter(&self) -> std::slice::Iter<u8> {
|
|
|
|
self.0.iter()
|
|
|
|
}
|
2015-08-17 05:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[deny(needless_range_loop, explicit_iter_loop, iter_next_loop)]
|
2015-08-30 11:10:59 +00:00
|
|
|
#[deny(unused_collect)]
|
2015-08-25 16:26:20 +00:00
|
|
|
#[allow(linkedlist)]
|
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
|
|
|
|
2015-09-02 10:41:51 +00:00
|
|
|
for i in 5..vec.len() { // not an error, not starting with 0
|
|
|
|
println!("{}", vec[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-17 05:23:57 +00:00
|
|
|
|
2015-08-25 16:26:20 +00:00
|
|
|
for _v in [1, 2, 3].iter() { } //~ERROR it is more idiomatic to loop over `&[
|
2015-08-31 06:29:34 +00:00
|
|
|
for _v in (&mut [1, 2, 3]).iter() { } // no error
|
2015-09-06 11:36:21 +00:00
|
|
|
for _v in [0; 32].iter() {} //~ERROR it is more idiomatic to loop over `&[
|
|
|
|
for _v in [0; 33].iter() {} // no error
|
2015-08-25 16:26:20 +00:00
|
|
|
let ll: LinkedList<()> = LinkedList::new();
|
|
|
|
for _v in ll.iter() { } //~ERROR it is more idiomatic to loop over `&ll`
|
|
|
|
let vd: VecDeque<()> = VecDeque::new();
|
|
|
|
for _v in vd.iter() { } //~ERROR it is more idiomatic to loop over `&vd`
|
|
|
|
let bh: BinaryHeap<()> = BinaryHeap::new();
|
|
|
|
for _v in bh.iter() { } //~ERROR it is more idiomatic to loop over `&bh`
|
|
|
|
let hm: HashMap<(), ()> = HashMap::new();
|
|
|
|
for _v in hm.iter() { } //~ERROR it is more idiomatic to loop over `&hm`
|
|
|
|
let bt: BTreeMap<(), ()> = BTreeMap::new();
|
|
|
|
for _v in bt.iter() { } //~ERROR it is more idiomatic to loop over `&bt`
|
|
|
|
let hs: HashSet<()> = HashSet::new();
|
|
|
|
for _v in hs.iter() { } //~ERROR it is more idiomatic to loop over `&hs`
|
|
|
|
let bs: BTreeSet<()> = BTreeSet::new();
|
|
|
|
for _v in bs.iter() { } //~ERROR it is more idiomatic to loop over `&bs`
|
|
|
|
|
2015-08-17 05:23:57 +00:00
|
|
|
for _v in vec.iter().next() { } //~ERROR you are iterating over `Iterator::next()`
|
|
|
|
|
|
|
|
let u = Unrelated(vec![]);
|
|
|
|
for _v in u.next() { } // no error
|
2015-08-25 16:26:20 +00:00
|
|
|
for _v in u.iter() { } // no error
|
2015-08-30 11:10:59 +00:00
|
|
|
|
|
|
|
let mut out = vec![];
|
|
|
|
vec.iter().map(|x| out.push(x)).collect::<Vec<_>>(); //~ERROR you are collect()ing an iterator
|
|
|
|
let _y = vec.iter().map(|x| out.push(x)).collect::<Vec<_>>(); // this is fine
|
2015-08-12 19:56:27 +00:00
|
|
|
}
|