diff --git a/src/concat_impl.rs b/src/concat_impl.rs index 450f7fce1..7d079e482 100644 --- a/src/concat_impl.rs +++ b/src/concat_impl.rs @@ -18,5 +18,5 @@ pub fn concat(iterable: I) -> I::Item where I: IntoIterator, I::Item: Extend<<::Item as IntoIterator>::Item> + IntoIterator + Default { - iterable.into_iter().fold1(|mut a, b| { a.extend(b); a }).unwrap_or_else(<_>::default) + iterable.into_iter().fold1(|mut a, b| { a.extend(b); a }).unwrap_or_default() } diff --git a/src/groupbylazy.rs b/src/groupbylazy.rs index 91c52ea59..37371f619 100644 --- a/src/groupbylazy.rs +++ b/src/groupbylazy.rs @@ -7,7 +7,7 @@ trait KeyFunction { fn call_mut(&mut self, arg: A) -> Self::Key; } -impl<'a, A, K, F: ?Sized> KeyFunction for F +impl KeyFunction for F where F: FnMut(A) -> K { type Key = K; @@ -37,7 +37,7 @@ impl ChunkIndex { } } -impl<'a, A> KeyFunction for ChunkIndex { +impl KeyFunction for ChunkIndex { type Key = usize; #[inline(always)] fn call_mut(&mut self, _arg: A) -> Self::Key { diff --git a/src/grouping_map.rs b/src/grouping_map.rs index 82ba1192b..bb5b582c9 100644 --- a/src/grouping_map.rs +++ b/src/grouping_map.rs @@ -289,7 +289,7 @@ impl GroupingMap where F: FnMut(&K, &V) -> CK, CK: Ord, { - self.max_by(|key, v1, v2| f(key, &v1).cmp(&f(key, &v2))) + self.max_by(|key, v1, v2| f(key, v1).cmp(&f(key, v2))) } /// Groups elements from the `GroupingMap` source by key and finds the minimum of each group. @@ -367,7 +367,7 @@ impl GroupingMap where F: FnMut(&K, &V) -> CK, CK: Ord, { - self.min_by(|key, v1, v2| f(key, &v1).cmp(&f(key, &v2))) + self.min_by(|key, v1, v2| f(key, v1).cmp(&f(key, v2))) } /// Groups elements from the `GroupingMap` source by key and find the maximum and minimum of @@ -480,7 +480,7 @@ impl GroupingMap where F: FnMut(&K, &V) -> CK, CK: Ord, { - self.minmax_by(|key, v1, v2| f(key, &v1).cmp(&f(key, &v2))) + self.minmax_by(|key, v1, v2| f(key, v1).cmp(&f(key, v2))) } /// Groups elements from the `GroupingMap` source by key and sums them. diff --git a/src/intersperse.rs b/src/intersperse.rs index 2c660d492..9de313ee2 100644 --- a/src/intersperse.rs +++ b/src/intersperse.rs @@ -107,8 +107,7 @@ impl Iterator for IntersperseWith self.iter.fold(accum, |accum, x| { let accum = f(accum, element.generate()); - let accum = f(accum, x); - accum + f(accum, x) }) } } diff --git a/src/lib.rs b/src/lib.rs index 6e86ab789..4b9d73e6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1797,7 +1797,7 @@ pub trait Itertools : Iterator { Some(if predicate(&first) { first } else { - self.find(|x| predicate(&x)).unwrap_or(first) + self.find(|x| predicate(x)).unwrap_or(first) }) } /// Returns `true` if the given item is present in this iterator. @@ -2694,7 +2694,6 @@ pub trait Itertools : Iterator { /// itertools::assert_equal(oldest_people_first, /// vec!["Jill", "Jack", "Jane", "John"]); /// ``` - /// ``` #[cfg(feature = "use_alloc")] fn sorted_by_cached_key(self, f: F) -> VecIntoIter where diff --git a/src/multipeek_impl.rs b/src/multipeek_impl.rs index 0ac9380b6..8b49c695e 100644 --- a/src/multipeek_impl.rs +++ b/src/multipeek_impl.rs @@ -71,10 +71,8 @@ impl PeekingNext for MultiPeek if let Some(r) = self.peek() { if !accept(r) { return None } } - } else { - if let Some(r) = self.buf.get(0) { - if !accept(r) { return None } - } + } else if let Some(r) = self.buf.get(0) { + if !accept(r) { return None } } self.next() } diff --git a/src/ziptuple.rs b/src/ziptuple.rs index b7902ae53..6d3a584c4 100644 --- a/src/ziptuple.rs +++ b/src/ziptuple.rs @@ -36,6 +36,7 @@ pub struct Zip { /// /// assert_eq!(results, [0 + 3, 10 + 7, 29, 36]); /// ``` +/// [`izip!()`]: crate::izip pub fn multizip(t: U) -> Zip where Zip: From, Zip: Iterator, diff --git a/tests/quick.rs b/tests/quick.rs index 5829d1c1d..1099e8e50 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -258,12 +258,12 @@ where let mut it = get_it(); for _ in 0..(counts.len() - 1) { - if let None = it.next() { + if it.next().is_none() { panic!("Iterator shouldn't be finished, may not be deterministic"); } } - if let None = it.next() { + if it.next().is_none() { break 'outer; } @@ -721,7 +721,7 @@ quickcheck! { assert_eq!(expected_first, curr_perm); - while let Some(next_perm) = perms.next() { + for next_perm in perms { assert!( next_perm > curr_perm, "next perm isn't greater-than current; next_perm={:?} curr_perm={:?} n={}", @@ -943,8 +943,7 @@ quickcheck! { fn fuzz_group_by_lazy_1(it: Iter) -> bool { let jt = it.clone(); let groups = it.group_by(|k| *k); - let res = itertools::equal(jt, groups.into_iter().flat_map(|(_, x)| x)); - res + itertools::equal(jt, groups.into_iter().flat_map(|(_, x)| x)) } } @@ -1286,7 +1285,7 @@ quickcheck! { .map(|i| (i % modulo, i)) .into_group_map() .into_iter() - .map(|(key, vals)| (key, vals.into_iter().fold(0u64, |acc, val| acc + val))) + .map(|(key, vals)| (key, vals.into_iter().sum())) .collect::>(); assert_eq!(lookup, group_map_lookup); @@ -1551,7 +1550,6 @@ quickcheck! { } quickcheck! { - #[test] fn counts(nums: Vec) -> TestResult { let counts = nums.iter().counts(); for (&item, &count) in counts.iter() { @@ -1602,7 +1600,7 @@ quickcheck! { fn is_fused(mut it: I) -> bool { - while let Some(_) = it.next() {} + for _ in it.by_ref() {} for _ in 0..10{ if it.next().is_some(){ return false; diff --git a/tests/specializations.rs b/tests/specializations.rs index 199cf562a..057e11c9f 100644 --- a/tests/specializations.rs +++ b/tests/specializations.rs @@ -129,7 +129,7 @@ quickcheck! { check_results_specialized!(it, |i| { let mut parameters_from_fold = vec![]; let fold_result = i.fold(vec![], |mut acc, v| { - parameters_from_fold.push((acc.clone(), v.clone())); + parameters_from_fold.push((acc.clone(), v)); acc.push(v); acc }); @@ -139,7 +139,7 @@ quickcheck! { let mut parameters_from_all = vec![]; let first = i.next(); let all_result = i.all(|x| { - parameters_from_all.push(x.clone()); + parameters_from_all.push(x); Some(x)==first }); (parameters_from_all, all_result) diff --git a/tests/test_core.rs b/tests/test_core.rs index a7b7449d3..cff0ed6be 100644 --- a/tests/test_core.rs +++ b/tests/test_core.rs @@ -116,7 +116,7 @@ fn chain2() { fn write_to() { let xs = [7, 9, 8]; let mut ys = [0; 5]; - let cnt = ys.iter_mut().set_from(xs.iter().map(|x| *x)); + let cnt = ys.iter_mut().set_from(xs.iter().copied()); assert!(cnt == xs.len()); assert!(ys == [7, 9, 8, 0, 0]); diff --git a/tests/test_std.rs b/tests/test_std.rs index 4463d912f..c9dc03fb2 100644 --- a/tests/test_std.rs +++ b/tests/test_std.rs @@ -123,12 +123,12 @@ fn unique() { #[test] fn intersperse() { let xs = ["a", "", "b", "c"]; - let v: Vec<&str> = xs.iter().map(|x| x.clone()).intersperse(", ").collect(); + let v: Vec<&str> = xs.iter().cloned().intersperse(", ").collect(); let text: String = v.concat(); assert_eq!(text, "a, , b, c".to_string()); let ys = [0, 1, 2, 3]; - let mut it = ys[..0].iter().map(|x| *x).intersperse(1); + let mut it = ys[..0].iter().copied().intersperse(1); assert!(it.next() == None); } @@ -474,7 +474,7 @@ impl qc::Arbitrary for Ran // Check that taking the k smallest is the same as // sorting then taking the k first elements -fn k_smallest_sort(i: I, k: u16) -> () +fn k_smallest_sort(i: I, k: u16) where I: Iterator + Clone, I::Item: Ord + Debug, @@ -538,10 +538,10 @@ fn sorted_by_cached_key() { fn test_multipeek() { let nums = vec![1u8,2,3,4,5]; - let mp = multipeek(nums.iter().map(|&x| x)); + let mp = multipeek(nums.iter().copied()); assert_eq!(nums, mp.collect::>()); - let mut mp = multipeek(nums.iter().map(|&x| x)); + let mut mp = multipeek(nums.iter().copied()); assert_eq!(mp.peek(), Some(&1)); assert_eq!(mp.next(), Some(1)); assert_eq!(mp.peek(), Some(&2)); @@ -579,7 +579,7 @@ fn test_multipeek_peeking_next() { use crate::it::PeekingNext; let nums = vec![1u8,2,3,4,5,6,7]; - let mut mp = multipeek(nums.iter().map(|&x| x)); + let mut mp = multipeek(nums.iter().copied()); assert_eq!(mp.peeking_next(|&x| x != 0), Some(1)); assert_eq!(mp.next(), Some(2)); assert_eq!(mp.peek(), Some(&3)); @@ -604,10 +604,10 @@ fn test_multipeek_peeking_next() { fn test_peek_nth() { let nums = vec![1u8,2,3,4,5]; - let iter = peek_nth(nums.iter().map(|&x| x)); + let iter = peek_nth(nums.iter().copied()); assert_eq!(nums, iter.collect::>()); - let mut iter = peek_nth(nums.iter().map(|&x| x)); + let mut iter = peek_nth(nums.iter().copied()); assert_eq!(iter.peek_nth(0), Some(&1)); assert_eq!(iter.peek_nth(0), Some(&1)); @@ -638,7 +638,7 @@ fn test_peek_nth() { fn test_peek_nth_peeking_next() { use it::PeekingNext; let nums = vec![1u8,2,3,4,5,6,7]; - let mut iter = peek_nth(nums.iter().map(|&x| x)); + let mut iter = peek_nth(nums.iter().copied()); assert_eq!(iter.peeking_next(|&x| x != 0), Some(1)); assert_eq!(iter.next(), Some(2)); @@ -694,7 +694,7 @@ fn group_by() { } } - let toupper = |ch: &char| ch.to_uppercase().nth(0).unwrap(); + let toupper = |ch: &char| ch.to_uppercase().next().unwrap(); // try all possible orderings for indices in permutohedron::Heap::new(&mut [0, 1, 2, 3]) { @@ -1091,9 +1091,9 @@ fn format() { let t2 = format!("{:?}", data.iter().format("--")); assert_eq!(t2, ans2); - let dataf = [1.1, 2.71828, -22.]; + let dataf = [1.1, 5.71828, -22.]; let t3 = format!("{:.2e}", dataf.iter().format(", ")); - assert_eq!(t3, "1.10e0, 2.72e0, -2.20e1"); + assert_eq!(t3, "1.10e0, 5.72e0, -2.20e1"); } #[test] @@ -1110,7 +1110,7 @@ fn fold_while() { let vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let sum = vec.into_iter().fold_while(0, |acc, item| { iterations += 1; - let new_sum = acc.clone() + item; + let new_sum = acc + item; if new_sum <= 20 { FoldWhile::Continue(new_sum) } else { @@ -1143,7 +1143,7 @@ fn tree_fold1() { "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", ]; for (i, &s) in x.iter().enumerate() { - let expected = if s == "" { None } else { Some(s.to_string()) }; + let expected = if s.is_empty() { None } else { Some(s.to_string()) }; let num_strings = (0..i).map(|x| x.to_string()); let actual = num_strings.tree_fold1(|a, b| format!("{} {} x", a, b)); assert_eq!(actual, expected); diff --git a/tests/zip.rs b/tests/zip.rs index 5801b4232..75157d34f 100644 --- a/tests/zip.rs +++ b/tests/zip.rs @@ -29,8 +29,8 @@ fn test_zip_longest_size_hint() { fn test_double_ended_zip_longest() { let xs = [1, 2, 3, 4, 5, 6]; let ys = [1, 2, 3, 7]; - let a = xs.iter().map(|&x| x); - let b = ys.iter().map(|&x| x); + let a = xs.iter().copied(); + let b = ys.iter().copied(); let mut it = a.zip_longest(b); assert_eq!(it.next(), Some(Both(1, 1))); assert_eq!(it.next(), Some(Both(2, 2))); @@ -45,8 +45,8 @@ fn test_double_ended_zip_longest() { fn test_double_ended_zip() { let xs = [1, 2, 3, 4, 5, 6]; let ys = [1, 2, 3, 7]; - let a = xs.iter().map(|&x| x); - let b = ys.iter().map(|&x| x); + let a = xs.iter().copied(); + let b = ys.iter().copied(); let mut it = multizip((a, b)); assert_eq!(it.next_back(), Some((4, 7))); assert_eq!(it.next_back(), Some((3, 3)));