2021-02-25 14:06:50 +00:00
|
|
|
// run-rustfix
|
|
|
|
// aux-build:option_helpers.rs
|
|
|
|
|
|
|
|
#![warn(clippy::iter_count)]
|
2021-02-25 16:54:51 +00:00
|
|
|
#![allow(
|
|
|
|
unused_variables,
|
|
|
|
array_into_iter,
|
|
|
|
unused_mut,
|
|
|
|
clippy::into_iter_on_ref,
|
|
|
|
clippy::unnecessary_operation
|
|
|
|
)]
|
2021-02-25 14:06:50 +00:00
|
|
|
|
|
|
|
extern crate option_helpers;
|
|
|
|
|
|
|
|
use option_helpers::IteratorFalsePositives;
|
|
|
|
use std::collections::{HashSet, VecDeque};
|
|
|
|
|
|
|
|
/// Struct to generate false positives for things with `.iter()`.
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct HasIter;
|
|
|
|
|
|
|
|
impl HasIter {
|
|
|
|
fn iter(self) -> IteratorFalsePositives {
|
|
|
|
IteratorFalsePositives { foo: 0 }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn iter_mut(self) -> IteratorFalsePositives {
|
|
|
|
IteratorFalsePositives { foo: 0 }
|
|
|
|
}
|
2021-02-25 16:54:51 +00:00
|
|
|
|
|
|
|
fn into_iter(self) -> IteratorFalsePositives {
|
|
|
|
IteratorFalsePositives { foo: 0 }
|
|
|
|
}
|
2021-02-25 14:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-02-25 16:54:51 +00:00
|
|
|
let mut vec = vec![0, 1, 2, 3];
|
2021-02-25 14:06:50 +00:00
|
|
|
let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
|
2021-02-25 16:54:51 +00:00
|
|
|
let mut vec_deque: VecDeque<_> = vec.iter().cloned().collect();
|
|
|
|
let mut hash_set = HashSet::new();
|
|
|
|
hash_set.insert(1);
|
2021-02-25 14:06:50 +00:00
|
|
|
|
2021-02-25 16:54:51 +00:00
|
|
|
&vec[..].len();
|
|
|
|
vec.len();
|
|
|
|
boxed_slice.len();
|
|
|
|
vec_deque.len();
|
|
|
|
hash_set.len();
|
|
|
|
|
|
|
|
vec.len();
|
|
|
|
&vec[..].len();
|
|
|
|
vec_deque.len();
|
|
|
|
|
|
|
|
&vec[..].len();
|
|
|
|
vec.len();
|
|
|
|
vec_deque.len();
|
2021-02-25 14:06:50 +00:00
|
|
|
|
|
|
|
// Make sure we don't lint for non-relevant types.
|
|
|
|
let false_positive = HasIter;
|
2021-02-25 16:54:51 +00:00
|
|
|
false_positive.iter().count();
|
|
|
|
false_positive.iter_mut().count();
|
|
|
|
false_positive.into_iter().count();
|
2021-02-25 14:06:50 +00:00
|
|
|
}
|