Fix various needless_range_loop false positives

This commit is contained in:
Oliver Schneider 2017-07-10 15:30:28 +02:00 committed by Oliver Schneider
parent d24868d036
commit 68948a5654
No known key found for this signature in database
GPG key ID: 1D5CB4FC597C3004
3 changed files with 95 additions and 43 deletions

View file

@ -249,8 +249,8 @@ fn main() {
for _v in u.iter() { } // no error
let mut out = vec![];
vec.iter().map(|x| out.push(x)).collect::<Vec<_>>();
let _y = vec.iter().map(|x| out.push(x)).collect::<Vec<_>>(); // this is fine
vec.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>();
let _y = vec.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>(); // this is fine
// Loop with explicit counter variable
let mut _index = 0;
@ -346,6 +346,18 @@ fn main() {
}
test_for_kv_map();
fn f<T>(_: &T, _: &T) -> bool { unimplemented!() }
fn g<T>(_: &mut [T], _: usize, _: usize) { unimplemented!() }
for i in 1..vec.len() {
if f(&vec[i - 1], &vec[i]) {
g(&mut vec, i - 1, i);
}
}
for mid in 1..vec.len() {
let (_, _) = vec.split_at(mid);
}
}
#[allow(used_underscore_binding)]
@ -358,3 +370,17 @@ fn test_for_kv_map() {
let _k = k;
}
}
#[allow(dead_code)]
fn partition<T:PartialOrd+Send>(v: &mut [T]) -> usize {
let pivot = v.len() - 1;
let mut i = 0;
for j in 0..pivot {
if v[j] <= v[pivot] {
v.swap(i, j);
i += 1;
}
}
v.swap(i, pivot);
i
}

View file

@ -419,8 +419,8 @@ error: you are iterating over `Iterator::next()` which is an Option; this will c
error: you are collect()ing an iterator and throwing away the result. Consider using an explicit for loop to exhaust the iterator
--> for_loop.rs:252:5
|
252 | vec.iter().map(|x| out.push(x)).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
252 | vec.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D unused-collect` implied by `-D warnings`