new lint: using collect() to just exhaust an iterator

Should use a for loop instead.
This commit is contained in:
Georg Brandl 2015-08-30 13:10:59 +02:00
parent b72ef5a173
commit 16df79a054
4 changed files with 27 additions and 2 deletions

View file

@ -15,6 +15,7 @@ impl Unrelated {
}
#[deny(needless_range_loop, explicit_iter_loop, iter_next_loop)]
#[deny(unused_collect)]
#[allow(linkedlist)]
fn main() {
let mut vec = vec![1, 2, 3, 4];
@ -56,4 +57,8 @@ fn main() {
let u = Unrelated(vec![]);
for _v in u.next() { } // no error
for _v in u.iter() { } // no error
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
}