From 71055de5947ccae3c54459723c48b533ee00abb4 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 08:56:42 +0200 Subject: [PATCH 01/18] fix clippy::needless_borrow --- src/grouping_map.rs | 6 +++--- src/lib.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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/lib.rs b/src/lib.rs index 6e86ab789..40d619665 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. From 0a7f5d4a586fdf96a33a804dba174a1b6a501a73 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 08:59:14 +0200 Subject: [PATCH 02/18] fix clippy::let_and_return --- src/intersperse.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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) }) } } From 28e0b959e72b18635a2bc353044e0465cae18365 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 08:59:58 +0200 Subject: [PATCH 03/18] fix clippy::extra_unused_lifetimes --- src/groupbylazy.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 { From 3010ae5357dfe33a03fecb9ad9a12def53586c04 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:01:24 +0200 Subject: [PATCH 04/18] fix clippy::unwrap_or_else_default --- src/concat_impl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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() } From e9a245a55ab88b9ed6dab224794c831234a11c0e Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:04:59 +0200 Subject: [PATCH 05/18] fix clippy::collapsible_else_if --- src/multipeek_impl.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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() } From c4c434bbfc9ceb10d25a3f597d559d555bab6a4a Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:12:42 +0200 Subject: [PATCH 06/18] fix clippy::clone_double_ref in tests --- tests/test_std.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_std.rs b/tests/test_std.rs index 4463d912f..026c1572b 100644 --- a/tests/test_std.rs +++ b/tests/test_std.rs @@ -123,7 +123,7 @@ 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()); From cfcc195d260b415ce7033274454b7f23c5fe1a7c Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:13:05 +0200 Subject: [PATCH 07/18] fix clippy::approx_constant in tests --- tests/test_std.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_std.rs b/tests/test_std.rs index 026c1572b..495f184d1 100644 --- a/tests/test_std.rs +++ b/tests/test_std.rs @@ -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] From 3a4a29a88b931ff80c76eae7a9cabe3930e4ffc5 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:14:28 +0200 Subject: [PATCH 08/18] fix clippy::while_let_on_iterator in tests --- tests/quick.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/quick.rs b/tests/quick.rs index 5829d1c1d..076278f2c 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -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={}", @@ -1602,7 +1602,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; From 95f238ba38bf2f802252b5e7fc2817d4f579dcb1 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:15:09 +0200 Subject: [PATCH 09/18] fix clippy::comparison_to_empty in tests --- tests/test_std.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_std.rs b/tests/test_std.rs index 495f184d1..be476b65f 100644 --- a/tests/test_std.rs +++ b/tests/test_std.rs @@ -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); From 758821e5a67eeabe42af45d3151fb1c456567b49 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:16:44 +0200 Subject: [PATCH 10/18] fix clippy::unnecessary_fold in tests --- tests/quick.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/quick.rs b/tests/quick.rs index 076278f2c..1810ff9d9 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -1286,7 +1286,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); From 9819fda23037b83f81ba7a7659903fb2f41e9dda Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:17:25 +0200 Subject: [PATCH 11/18] fix clippy::clone_on_copy in tests --- tests/specializations.rs | 4 ++-- tests/test_std.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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_std.rs b/tests/test_std.rs index be476b65f..ca8d4f4af 100644 --- a/tests/test_std.rs +++ b/tests/test_std.rs @@ -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 { From 738382836e7fa13df88c8bf8328dad53806934a0 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:17:56 +0200 Subject: [PATCH 12/18] fix clippy::let_and_return in tests --- tests/quick.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/quick.rs b/tests/quick.rs index 1810ff9d9..ffd219a32 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -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)) } } From a989b3a5536531e164933b8fc3581c73f428a267 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:18:25 +0200 Subject: [PATCH 13/18] fix clippy::iter_nth_zero in tests --- tests/test_std.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_std.rs b/tests/test_std.rs index ca8d4f4af..79c54cce5 100644 --- a/tests/test_std.rs +++ b/tests/test_std.rs @@ -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]) { From fe06b67094510e7cac7aac902130b3625593141c Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:22:24 +0200 Subject: [PATCH 14/18] fix clippy::map_clone in tests --- tests/test_core.rs | 2 +- tests/test_std.rs | 14 +++++++------- tests/zip.rs | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) 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 79c54cce5..b1d0f4e8e 100644 --- a/tests/test_std.rs +++ b/tests/test_std.rs @@ -128,7 +128,7 @@ fn intersperse() { 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); } @@ -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)); 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))); From a016b870db8179573ed2da101e3f5854f7afb048 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:26:30 +0200 Subject: [PATCH 15/18] fix clippy::redundant_pattern_matching in tests --- tests/quick.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/quick.rs b/tests/quick.rs index ffd219a32..c1b3819ce 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; } From 2e6cf7fe5224397aafd95e8e3c5b24225511c7e7 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:38:57 +0200 Subject: [PATCH 16/18] fix duplicate_macro_attributes in tests the #[test] macro is automatically applied to all functions inside of the `quickcheck!` macro, so this one was redundant --- tests/quick.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/quick.rs b/tests/quick.rs index c1b3819ce..1099e8e50 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -1550,7 +1550,6 @@ quickcheck! { } quickcheck! { - #[test] fn counts(nums: Vec) -> TestResult { let counts = nums.iter().counts(); for (&item, &count) in counts.iter() { From 5b3b648c926c7bfa733f178b90432b26a1dce2ad Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:40:18 +0200 Subject: [PATCH 17/18] fix clippy::unused_unit in tests --- tests/test_std.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_std.rs b/tests/test_std.rs index b1d0f4e8e..c9dc03fb2 100644 --- a/tests/test_std.rs +++ b/tests/test_std.rs @@ -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, From aac4268547990d1f376742555eb6331e0565ee2d Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Thu, 2 Jun 2022 13:51:49 +0200 Subject: [PATCH 18/18] fix rustdoc warnings --- src/lib.rs | 1 - src/ziptuple.rs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 40d619665..4b9d73e6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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/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,