Skip to content

Commit 5c11e00

Browse files
bors[bot]hellow554
andauthored
Merge #624
624: Hellow554 lints 1 r=phimuemue a=phimuemue First batch of #618. bors r+ Co-authored-by: Marcel Hellwig <[email protected]>
2 parents 28cff76 + aac4268 commit 5c11e00

12 files changed

+38
-43
lines changed

src/concat_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ 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-
iterable.into_iter().fold1(|mut a, b| { a.extend(b); a }).unwrap_or_else(<_>::default)
21+
iterable.into_iter().fold1(|mut a, b| { a.extend(b); a }).unwrap_or_default()
2222
}

src/groupbylazy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait KeyFunction<A> {
77
fn call_mut(&mut self, arg: A) -> Self::Key;
88
}
99

10-
impl<'a, A, K, F: ?Sized> KeyFunction<A> for F
10+
impl<A, K, F: ?Sized> KeyFunction<A> for F
1111
where F: FnMut(A) -> K
1212
{
1313
type Key = K;
@@ -37,7 +37,7 @@ impl ChunkIndex {
3737
}
3838
}
3939

40-
impl<'a, A> KeyFunction<A> for ChunkIndex {
40+
impl<A> KeyFunction<A> for ChunkIndex {
4141
type Key = usize;
4242
#[inline(always)]
4343
fn call_mut(&mut self, _arg: A) -> Self::Key {

src/grouping_map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<I, K, V> GroupingMap<I>
289289
where F: FnMut(&K, &V) -> CK,
290290
CK: Ord,
291291
{
292-
self.max_by(|key, v1, v2| f(key, &v1).cmp(&f(key, &v2)))
292+
self.max_by(|key, v1, v2| f(key, v1).cmp(&f(key, v2)))
293293
}
294294

295295
/// Groups elements from the `GroupingMap` source by key and finds the minimum of each group.
@@ -367,7 +367,7 @@ impl<I, K, V> GroupingMap<I>
367367
where F: FnMut(&K, &V) -> CK,
368368
CK: Ord,
369369
{
370-
self.min_by(|key, v1, v2| f(key, &v1).cmp(&f(key, &v2)))
370+
self.min_by(|key, v1, v2| f(key, v1).cmp(&f(key, v2)))
371371
}
372372

373373
/// Groups elements from the `GroupingMap` source by key and find the maximum and minimum of
@@ -480,7 +480,7 @@ impl<I, K, V> GroupingMap<I>
480480
where F: FnMut(&K, &V) -> CK,
481481
CK: Ord,
482482
{
483-
self.minmax_by(|key, v1, v2| f(key, &v1).cmp(&f(key, &v2)))
483+
self.minmax_by(|key, v1, v2| f(key, v1).cmp(&f(key, v2)))
484484
}
485485

486486
/// Groups elements from the `GroupingMap` source by key and sums them.

src/intersperse.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ impl<I, ElemF> Iterator for IntersperseWith<I, ElemF>
107107
self.iter.fold(accum,
108108
|accum, x| {
109109
let accum = f(accum, element.generate());
110-
let accum = f(accum, x);
111-
accum
110+
f(accum, x)
112111
})
113112
}
114113
}

src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ pub trait Itertools : Iterator {
17971797
Some(if predicate(&first) {
17981798
first
17991799
} else {
1800-
self.find(|x| predicate(&x)).unwrap_or(first)
1800+
self.find(|x| predicate(x)).unwrap_or(first)
18011801
})
18021802
}
18031803
/// Returns `true` if the given item is present in this iterator.
@@ -2694,7 +2694,6 @@ pub trait Itertools : Iterator {
26942694
/// itertools::assert_equal(oldest_people_first,
26952695
/// vec!["Jill", "Jack", "Jane", "John"]);
26962696
/// ```
2697-
/// ```
26982697
#[cfg(feature = "use_alloc")]
26992698
fn sorted_by_cached_key<K, F>(self, f: F) -> VecIntoIter<Self::Item>
27002699
where

src/multipeek_impl.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ impl<I> PeekingNext for MultiPeek<I>
7171
if let Some(r) = self.peek() {
7272
if !accept(r) { return None }
7373
}
74-
} else {
75-
if let Some(r) = self.buf.get(0) {
76-
if !accept(r) { return None }
77-
}
74+
} else if let Some(r) = self.buf.get(0) {
75+
if !accept(r) { return None }
7876
}
7977
self.next()
8078
}

src/ziptuple.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub struct Zip<T> {
3636
///
3737
/// assert_eq!(results, [0 + 3, 10 + 7, 29, 36]);
3838
/// ```
39+
/// [`izip!()`]: crate::izip
3940
pub fn multizip<T, U>(t: U) -> Zip<T>
4041
where Zip<T>: From<U>,
4142
Zip<T>: Iterator,

tests/quick.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,12 @@ where
258258
let mut it = get_it();
259259

260260
for _ in 0..(counts.len() - 1) {
261-
if let None = it.next() {
261+
if it.next().is_none() {
262262
panic!("Iterator shouldn't be finished, may not be deterministic");
263263
}
264264
}
265265

266-
if let None = it.next() {
266+
if it.next().is_none() {
267267
break 'outer;
268268
}
269269

@@ -721,7 +721,7 @@ quickcheck! {
721721

722722
assert_eq!(expected_first, curr_perm);
723723

724-
while let Some(next_perm) = perms.next() {
724+
for next_perm in perms {
725725
assert!(
726726
next_perm > curr_perm,
727727
"next perm isn't greater-than current; next_perm={:?} curr_perm={:?} n={}",
@@ -943,8 +943,7 @@ quickcheck! {
943943
fn fuzz_group_by_lazy_1(it: Iter<u8>) -> bool {
944944
let jt = it.clone();
945945
let groups = it.group_by(|k| *k);
946-
let res = itertools::equal(jt, groups.into_iter().flat_map(|(_, x)| x));
947-
res
946+
itertools::equal(jt, groups.into_iter().flat_map(|(_, x)| x))
948947
}
949948
}
950949

@@ -1286,7 +1285,7 @@ quickcheck! {
12861285
.map(|i| (i % modulo, i))
12871286
.into_group_map()
12881287
.into_iter()
1289-
.map(|(key, vals)| (key, vals.into_iter().fold(0u64, |acc, val| acc + val)))
1288+
.map(|(key, vals)| (key, vals.into_iter().sum()))
12901289
.collect::<HashMap<_,_>>();
12911290
assert_eq!(lookup, group_map_lookup);
12921291

@@ -1551,7 +1550,6 @@ quickcheck! {
15511550
}
15521551

15531552
quickcheck! {
1554-
#[test]
15551553
fn counts(nums: Vec<isize>) -> TestResult {
15561554
let counts = nums.iter().counts();
15571555
for (&item, &count) in counts.iter() {
@@ -1602,7 +1600,7 @@ quickcheck! {
16021600

16031601
fn is_fused<I: Iterator>(mut it: I) -> bool
16041602
{
1605-
while let Some(_) = it.next() {}
1603+
for _ in it.by_ref() {}
16061604
for _ in 0..10{
16071605
if it.next().is_some(){
16081606
return false;

tests/specializations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ quickcheck! {
129129
check_results_specialized!(it, |i| {
130130
let mut parameters_from_fold = vec![];
131131
let fold_result = i.fold(vec![], |mut acc, v| {
132-
parameters_from_fold.push((acc.clone(), v.clone()));
132+
parameters_from_fold.push((acc.clone(), v));
133133
acc.push(v);
134134
acc
135135
});
@@ -139,7 +139,7 @@ quickcheck! {
139139
let mut parameters_from_all = vec![];
140140
let first = i.next();
141141
let all_result = i.all(|x| {
142-
parameters_from_all.push(x.clone());
142+
parameters_from_all.push(x);
143143
Some(x)==first
144144
});
145145
(parameters_from_all, all_result)

tests/test_core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn chain2() {
116116
fn write_to() {
117117
let xs = [7, 9, 8];
118118
let mut ys = [0; 5];
119-
let cnt = ys.iter_mut().set_from(xs.iter().map(|x| *x));
119+
let cnt = ys.iter_mut().set_from(xs.iter().copied());
120120
assert!(cnt == xs.len());
121121
assert!(ys == [7, 9, 8, 0, 0]);
122122

tests/test_std.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ fn unique() {
123123
#[test]
124124
fn intersperse() {
125125
let xs = ["a", "", "b", "c"];
126-
let v: Vec<&str> = xs.iter().map(|x| x.clone()).intersperse(", ").collect();
126+
let v: Vec<&str> = xs.iter().cloned().intersperse(", ").collect();
127127
let text: String = v.concat();
128128
assert_eq!(text, "a, , b, c".to_string());
129129

130130
let ys = [0, 1, 2, 3];
131-
let mut it = ys[..0].iter().map(|x| *x).intersperse(1);
131+
let mut it = ys[..0].iter().copied().intersperse(1);
132132
assert!(it.next() == None);
133133
}
134134

@@ -474,7 +474,7 @@ impl<T: Clone + Send, R: Clone + Rng + SeedableRng + Send> qc::Arbitrary for Ran
474474

475475
// Check that taking the k smallest is the same as
476476
// sorting then taking the k first elements
477-
fn k_smallest_sort<I>(i: I, k: u16) -> ()
477+
fn k_smallest_sort<I>(i: I, k: u16)
478478
where
479479
I: Iterator + Clone,
480480
I::Item: Ord + Debug,
@@ -538,10 +538,10 @@ fn sorted_by_cached_key() {
538538
fn test_multipeek() {
539539
let nums = vec![1u8,2,3,4,5];
540540

541-
let mp = multipeek(nums.iter().map(|&x| x));
541+
let mp = multipeek(nums.iter().copied());
542542
assert_eq!(nums, mp.collect::<Vec<_>>());
543543

544-
let mut mp = multipeek(nums.iter().map(|&x| x));
544+
let mut mp = multipeek(nums.iter().copied());
545545
assert_eq!(mp.peek(), Some(&1));
546546
assert_eq!(mp.next(), Some(1));
547547
assert_eq!(mp.peek(), Some(&2));
@@ -579,7 +579,7 @@ fn test_multipeek_peeking_next() {
579579
use crate::it::PeekingNext;
580580
let nums = vec![1u8,2,3,4,5,6,7];
581581

582-
let mut mp = multipeek(nums.iter().map(|&x| x));
582+
let mut mp = multipeek(nums.iter().copied());
583583
assert_eq!(mp.peeking_next(|&x| x != 0), Some(1));
584584
assert_eq!(mp.next(), Some(2));
585585
assert_eq!(mp.peek(), Some(&3));
@@ -604,10 +604,10 @@ fn test_multipeek_peeking_next() {
604604
fn test_peek_nth() {
605605
let nums = vec![1u8,2,3,4,5];
606606

607-
let iter = peek_nth(nums.iter().map(|&x| x));
607+
let iter = peek_nth(nums.iter().copied());
608608
assert_eq!(nums, iter.collect::<Vec<_>>());
609609

610-
let mut iter = peek_nth(nums.iter().map(|&x| x));
610+
let mut iter = peek_nth(nums.iter().copied());
611611

612612
assert_eq!(iter.peek_nth(0), Some(&1));
613613
assert_eq!(iter.peek_nth(0), Some(&1));
@@ -638,7 +638,7 @@ fn test_peek_nth() {
638638
fn test_peek_nth_peeking_next() {
639639
use it::PeekingNext;
640640
let nums = vec![1u8,2,3,4,5,6,7];
641-
let mut iter = peek_nth(nums.iter().map(|&x| x));
641+
let mut iter = peek_nth(nums.iter().copied());
642642

643643
assert_eq!(iter.peeking_next(|&x| x != 0), Some(1));
644644
assert_eq!(iter.next(), Some(2));
@@ -694,7 +694,7 @@ fn group_by() {
694694
}
695695
}
696696

697-
let toupper = |ch: &char| ch.to_uppercase().nth(0).unwrap();
697+
let toupper = |ch: &char| ch.to_uppercase().next().unwrap();
698698

699699
// try all possible orderings
700700
for indices in permutohedron::Heap::new(&mut [0, 1, 2, 3]) {
@@ -1091,9 +1091,9 @@ fn format() {
10911091
let t2 = format!("{:?}", data.iter().format("--"));
10921092
assert_eq!(t2, ans2);
10931093

1094-
let dataf = [1.1, 2.71828, -22.];
1094+
let dataf = [1.1, 5.71828, -22.];
10951095
let t3 = format!("{:.2e}", dataf.iter().format(", "));
1096-
assert_eq!(t3, "1.10e0, 2.72e0, -2.20e1");
1096+
assert_eq!(t3, "1.10e0, 5.72e0, -2.20e1");
10971097
}
10981098

10991099
#[test]
@@ -1110,7 +1110,7 @@ fn fold_while() {
11101110
let vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
11111111
let sum = vec.into_iter().fold_while(0, |acc, item| {
11121112
iterations += 1;
1113-
let new_sum = acc.clone() + item;
1113+
let new_sum = acc + item;
11141114
if new_sum <= 20 {
11151115
FoldWhile::Continue(new_sum)
11161116
} else {
@@ -1143,7 +1143,7 @@ fn tree_fold1() {
11431143
"0 1 x 2 3 x x 4 5 x 6 7 x x x 8 9 x 10 11 x x 12 13 x 14 15 x x x x",
11441144
];
11451145
for (i, &s) in x.iter().enumerate() {
1146-
let expected = if s == "" { None } else { Some(s.to_string()) };
1146+
let expected = if s.is_empty() { None } else { Some(s.to_string()) };
11471147
let num_strings = (0..i).map(|x| x.to_string());
11481148
let actual = num_strings.tree_fold1(|a, b| format!("{} {} x", a, b));
11491149
assert_eq!(actual, expected);

tests/zip.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ fn test_zip_longest_size_hint() {
2929
fn test_double_ended_zip_longest() {
3030
let xs = [1, 2, 3, 4, 5, 6];
3131
let ys = [1, 2, 3, 7];
32-
let a = xs.iter().map(|&x| x);
33-
let b = ys.iter().map(|&x| x);
32+
let a = xs.iter().copied();
33+
let b = ys.iter().copied();
3434
let mut it = a.zip_longest(b);
3535
assert_eq!(it.next(), Some(Both(1, 1)));
3636
assert_eq!(it.next(), Some(Both(2, 2)));
@@ -45,8 +45,8 @@ fn test_double_ended_zip_longest() {
4545
fn test_double_ended_zip() {
4646
let xs = [1, 2, 3, 4, 5, 6];
4747
let ys = [1, 2, 3, 7];
48-
let a = xs.iter().map(|&x| x);
49-
let b = ys.iter().map(|&x| x);
48+
let a = xs.iter().copied();
49+
let b = ys.iter().copied();
5050
let mut it = multizip((a, b));
5151
assert_eq!(it.next_back(), Some((4, 7)));
5252
assert_eq!(it.next_back(), Some((3, 3)));

0 commit comments

Comments
 (0)