new lint: using collect() to just exhaust an iterator
Should use a for loop instead.
This commit is contained in:
parent
b72ef5a173
commit
16df79a054
4 changed files with 27 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue