Skip to content

Commit 5459a26

Browse files
bors[bot]hellow554
andauthored
Merge #627
627: Hellow554 lints 2 r=phimuemue a=phimuemue Second batch of #618. Co-authored-by: Marcel Hellwig <[email protected]>
2 parents 1383a39 + a16c01c commit 5459a26

9 files changed

+32
-50
lines changed

src/adaptors/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,7 @@ impl<I, J> Iterator for Product<I, J>
327327
}
328328
Some(x) => x
329329
};
330-
match self.a_cur {
331-
None => None,
332-
Some(ref a) => {
333-
Some((a.clone(), elt_b))
334-
}
335-
}
330+
self.a_cur.as_ref().map(|a| (a.clone(), elt_b))
336331
}
337332

338333
fn size_hint(&self) -> (usize, Option<usize>) {

src/combinations_with_replacement.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ where
6464
// If this is the first iteration, return early
6565
if self.first {
6666
// In empty edge cases, stop iterating immediately
67-
return if self.indices.len() != 0 && !self.pool.get_next() {
67+
return if !(self.indices.is_empty() || self.pool.get_next()) {
6868
None
6969
// Otherwise, yield the initial state
7070
} else {

src/concat_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ pub fn concat<I>(iterable: I) -> I::Item
1818
where I: IntoIterator,
1919
I::Item: Extend<<<I as IntoIterator>::Item as IntoIterator>::Item> + IntoIterator + Default
2020
{
21+
#[allow(deprecated)] //TODO: once msrv hits 1.51. replace `fold1` with `reduce`
2122
iterable.into_iter().fold1(|mut a, b| { a.extend(b); a }).unwrap_or_default()
2223
}

src/kmerge_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ impl<I, F> Iterator for KMergeBy<I, F>
213213
}
214214

215215
fn size_hint(&self) -> (usize, Option<usize>) {
216+
#[allow(deprecated)] //TODO: once msrv hits 1.51. replace `fold1` with `reduce`
216217
self.heap.iter()
217218
.map(|i| i.size_hint())
218219
.fold1(size_hint::add)

src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1748,12 +1748,10 @@ pub trait Itertools : Iterator {
17481748
fn find_position<P>(&mut self, mut pred: P) -> Option<(usize, Self::Item)>
17491749
where P: FnMut(&Self::Item) -> bool
17501750
{
1751-
let mut index = 0usize;
1752-
for elt in self {
1751+
for (index, elt) in self.enumerate() {
17531752
if pred(&elt) {
17541753
return Some((index, elt));
17551754
}
1756-
index += 1;
17571755
}
17581756
None
17591757
}

tests/adaptors_no_collect.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ impl Iterator for PanickingCounter {
1111
fn next(&mut self) -> Option<Self::Item> {
1212
self.curr += 1;
1313

14-
if self.curr == self.max {
15-
panic!(
16-
"Input iterator reached maximum of {} suggesting collection by adaptor",
17-
self.max
18-
);
19-
}
14+
assert_ne!(
15+
self.curr, self.max,
16+
"Input iterator reached maximum of {} suggesting collection by adaptor",
17+
self.max
18+
);
2019

2120
Some(())
2221
}

tests/quick.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ quickcheck! {
438438
}
439439
assert_eq!(answer, actual);
440440

441-
assert_eq!(answer.into_iter().last(), a.clone().multi_cartesian_product().last());
441+
assert_eq!(answer.into_iter().last(), a.multi_cartesian_product().last());
442442
}
443443

444444
#[allow(deprecated)]
@@ -498,15 +498,13 @@ quickcheck! {
498498
exact_size(it)
499499
}
500500

501-
fn equal_merge(a: Vec<i16>, b: Vec<i16>) -> bool {
502-
let mut sa = a.clone();
503-
let mut sb = b.clone();
504-
sa.sort();
505-
sb.sort();
506-
let mut merged = sa.clone();
507-
merged.extend(sb.iter().cloned());
501+
fn equal_merge(mut a: Vec<i16>, mut b: Vec<i16>) -> bool {
502+
a.sort();
503+
b.sort();
504+
let mut merged = a.clone();
505+
merged.extend(b.iter().cloned());
508506
merged.sort();
509-
itertools::equal(&merged, sa.iter().merge(&sb))
507+
itertools::equal(&merged, a.iter().merge(&b))
510508
}
511509
fn size_merge(a: Iter<u16>, b: Iter<u16>) -> bool {
512510
correct_size_hint(a.merge(b))
@@ -517,7 +515,7 @@ quickcheck! {
517515
exact_size(multizip((a, b, c)))
518516
}
519517
fn size_zip_rc(a: Iter<i16>, b: Iter<i16>) -> bool {
520-
let rc = rciter(a.clone());
518+
let rc = rciter(a);
521519
correct_size_hint(multizip((&rc, &rc, b)))
522520
}
523521

@@ -526,19 +524,16 @@ quickcheck! {
526524
correct_size_hint(izip!(filt, b.clone(), c.clone())) &&
527525
exact_size(izip!(a, b, c))
528526
}
529-
fn equal_kmerge(a: Vec<i16>, b: Vec<i16>, c: Vec<i16>) -> bool {
527+
fn equal_kmerge(mut a: Vec<i16>, mut b: Vec<i16>, mut c: Vec<i16>) -> bool {
530528
use itertools::free::kmerge;
531-
let mut sa = a.clone();
532-
let mut sb = b.clone();
533-
let mut sc = c.clone();
534-
sa.sort();
535-
sb.sort();
536-
sc.sort();
537-
let mut merged = sa.clone();
538-
merged.extend(sb.iter().cloned());
539-
merged.extend(sc.iter().cloned());
529+
a.sort();
530+
b.sort();
531+
c.sort();
532+
let mut merged = a.clone();
533+
merged.extend(b.iter().cloned());
534+
merged.extend(c.iter().cloned());
540535
merged.sort();
541-
itertools::equal(merged.into_iter(), kmerge(vec![sa, sb, sc]))
536+
itertools::equal(merged.into_iter(), kmerge(vec![a, b, c]))
542537
}
543538

544539
// Any number of input iterators
@@ -610,15 +605,15 @@ quickcheck! {
610605
fn size_2_zip_longest(a: Iter<i16>, b: Iter<i16>) -> bool {
611606
let it = a.clone().zip_longest(b.clone());
612607
let jt = a.clone().zip_longest(b.clone());
613-
itertools::equal(a.clone(),
608+
itertools::equal(a,
614609
it.filter_map(|elt| match elt {
615610
EitherOrBoth::Both(x, _) => Some(x),
616611
EitherOrBoth::Left(x) => Some(x),
617612
_ => None,
618613
}
619614
))
620615
&&
621-
itertools::equal(b.clone(),
616+
itertools::equal(b,
622617
jt.filter_map(|elt| match elt {
623618
EitherOrBoth::Both(_, y) => Some(y),
624619
EitherOrBoth::Right(y) => Some(y),

tests/test_core.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,10 @@ fn batching() {
180180
let ys = [(0, 1), (2, 1)];
181181

182182
// An iterator that gathers elements up in pairs
183-
let pit = xs.iter().cloned().batching(|it| {
184-
match it.next() {
185-
None => None,
186-
Some(x) => match it.next() {
187-
None => None,
188-
Some(y) => Some((x, y)),
189-
}
190-
}
191-
});
183+
let pit = xs
184+
.iter()
185+
.cloned()
186+
.batching(|it| it.next().and_then(|x| it.next().map(|y| (x, y))));
192187
it::assert_equal(pit, ys.iter().cloned());
193188
}
194189

tests/test_std.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use paste;
2-
use permutohedron;
31
use quickcheck as qc;
42
use rand::{distributions::{Distribution, Standard}, Rng, SeedableRng, rngs::StdRng};
53
use rand::{seq::SliceRandom, thread_rng};

0 commit comments

Comments
 (0)