Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hellow554 lints 2 #627

Merged
merged 8 commits into from Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/adaptors/mod.rs
Expand Up @@ -327,12 +327,7 @@ impl<I, J> Iterator for Product<I, J>
}
Some(x) => x
};
match self.a_cur {
None => None,
Some(ref a) => {
Some((a.clone(), elt_b))
}
}
self.a_cur.as_ref().map(|a| (a.clone(), elt_b))
}

fn size_hint(&self) -> (usize, Option<usize>) {
Expand Down
2 changes: 1 addition & 1 deletion src/combinations_with_replacement.rs
Expand Up @@ -64,7 +64,7 @@ where
// If this is the first iteration, return early
if self.first {
// In empty edge cases, stop iterating immediately
return if self.indices.len() != 0 && !self.pool.get_next() {
return if !(self.indices.is_empty() || self.pool.get_next()) {
None
// Otherwise, yield the initial state
} else {
Expand Down
1 change: 1 addition & 0 deletions src/concat_impl.rs
Expand Up @@ -18,5 +18,6 @@ pub fn concat<I>(iterable: I) -> I::Item
where I: IntoIterator,
I::Item: Extend<<<I as IntoIterator>::Item as IntoIterator>::Item> + IntoIterator + Default
{
#[allow(deprecated)] //TODO: once msrv hits 1.51. replace `fold1` with `reduce`
iterable.into_iter().fold1(|mut a, b| { a.extend(b); a }).unwrap_or_default()
}
1 change: 1 addition & 0 deletions src/kmerge_impl.rs
Expand Up @@ -213,6 +213,7 @@ impl<I, F> Iterator for KMergeBy<I, F>
}

fn size_hint(&self) -> (usize, Option<usize>) {
#[allow(deprecated)] //TODO: once msrv hits 1.51. replace `fold1` with `reduce`
self.heap.iter()
.map(|i| i.size_hint())
.fold1(size_hint::add)
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Expand Up @@ -1748,12 +1748,10 @@ pub trait Itertools : Iterator {
fn find_position<P>(&mut self, mut pred: P) -> Option<(usize, Self::Item)>
where P: FnMut(&Self::Item) -> bool
{
let mut index = 0usize;
for elt in self {
for (index, elt) in self.enumerate() {
if pred(&elt) {
return Some((index, elt));
}
index += 1;
}
None
}
Expand Down
11 changes: 5 additions & 6 deletions tests/adaptors_no_collect.rs
Expand Up @@ -11,12 +11,11 @@ impl Iterator for PanickingCounter {
fn next(&mut self) -> Option<Self::Item> {
self.curr += 1;

if self.curr == self.max {
panic!(
"Input iterator reached maximum of {} suggesting collection by adaptor",
self.max
);
}
assert_ne!(
self.curr, self.max,
"Input iterator reached maximum of {} suggesting collection by adaptor",
self.max
);

Some(())
}
Expand Down
41 changes: 18 additions & 23 deletions tests/quick.rs
Expand Up @@ -438,7 +438,7 @@ quickcheck! {
}
assert_eq!(answer, actual);

assert_eq!(answer.into_iter().last(), a.clone().multi_cartesian_product().last());
assert_eq!(answer.into_iter().last(), a.multi_cartesian_product().last());
}

#[allow(deprecated)]
Expand Down Expand Up @@ -498,15 +498,13 @@ quickcheck! {
exact_size(it)
}

fn equal_merge(a: Vec<i16>, b: Vec<i16>) -> bool {
let mut sa = a.clone();
let mut sb = b.clone();
sa.sort();
sb.sort();
let mut merged = sa.clone();
merged.extend(sb.iter().cloned());
fn equal_merge(mut a: Vec<i16>, mut b: Vec<i16>) -> bool {
a.sort();
b.sort();
let mut merged = a.clone();
merged.extend(b.iter().cloned());
merged.sort();
itertools::equal(&merged, sa.iter().merge(&sb))
itertools::equal(&merged, a.iter().merge(&b))
}
fn size_merge(a: Iter<u16>, b: Iter<u16>) -> bool {
correct_size_hint(a.merge(b))
Expand All @@ -517,7 +515,7 @@ quickcheck! {
exact_size(multizip((a, b, c)))
}
fn size_zip_rc(a: Iter<i16>, b: Iter<i16>) -> bool {
let rc = rciter(a.clone());
let rc = rciter(a);
correct_size_hint(multizip((&rc, &rc, b)))
}

Expand All @@ -526,19 +524,16 @@ quickcheck! {
correct_size_hint(izip!(filt, b.clone(), c.clone())) &&
exact_size(izip!(a, b, c))
}
fn equal_kmerge(a: Vec<i16>, b: Vec<i16>, c: Vec<i16>) -> bool {
fn equal_kmerge(mut a: Vec<i16>, mut b: Vec<i16>, mut c: Vec<i16>) -> bool {
use itertools::free::kmerge;
let mut sa = a.clone();
let mut sb = b.clone();
let mut sc = c.clone();
sa.sort();
sb.sort();
sc.sort();
let mut merged = sa.clone();
merged.extend(sb.iter().cloned());
merged.extend(sc.iter().cloned());
a.sort();
b.sort();
c.sort();
let mut merged = a.clone();
merged.extend(b.iter().cloned());
merged.extend(c.iter().cloned());
merged.sort();
itertools::equal(merged.into_iter(), kmerge(vec![sa, sb, sc]))
itertools::equal(merged.into_iter(), kmerge(vec![a, b, c]))
}

// Any number of input iterators
Expand Down Expand Up @@ -610,15 +605,15 @@ quickcheck! {
fn size_2_zip_longest(a: Iter<i16>, b: Iter<i16>) -> bool {
let it = a.clone().zip_longest(b.clone());
let jt = a.clone().zip_longest(b.clone());
itertools::equal(a.clone(),
itertools::equal(a,
it.filter_map(|elt| match elt {
EitherOrBoth::Both(x, _) => Some(x),
EitherOrBoth::Left(x) => Some(x),
_ => None,
}
))
&&
itertools::equal(b.clone(),
itertools::equal(b,
jt.filter_map(|elt| match elt {
EitherOrBoth::Both(_, y) => Some(y),
EitherOrBoth::Right(y) => Some(y),
Expand Down
13 changes: 4 additions & 9 deletions tests/test_core.rs
Expand Up @@ -180,15 +180,10 @@ fn batching() {
let ys = [(0, 1), (2, 1)];

// An iterator that gathers elements up in pairs
let pit = xs.iter().cloned().batching(|it| {
match it.next() {
None => None,
Some(x) => match it.next() {
None => None,
Some(y) => Some((x, y)),
}
}
});
let pit = xs
.iter()
.cloned()
.batching(|it| it.next().and_then(|x| it.next().map(|y| (x, y))));
it::assert_equal(pit, ys.iter().cloned());
}

Expand Down
2 changes: 0 additions & 2 deletions tests/test_std.rs
@@ -1,5 +1,3 @@
use paste;
use permutohedron;
use quickcheck as qc;
use rand::{distributions::{Distribution, Standard}, Rng, SeedableRng, rngs::StdRng};
use rand::{seq::SliceRandom, thread_rng};
Expand Down