From 700424b752d6690a54fba82a29eec185e049aa91 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:04:09 +0200 Subject: [PATCH 1/8] add clippy.toml --- clippy.toml | 1 + 1 file changed, 1 insertion(+) create mode 100644 clippy.toml diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 000000000..0a5485386 --- /dev/null +++ b/clippy.toml @@ -0,0 +1 @@ +msrv = "1.36.0" From c3027a9934cf9ed3d76e2029667d6da1cb11df41 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 3 Jun 2022 09:13:29 +0200 Subject: [PATCH 2/8] allow clippy::absurd_extreme_comparisons in tests --- tests/quick.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/quick.rs b/tests/quick.rs index e5b686823..5c73d20a9 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -1548,6 +1548,7 @@ quickcheck! { fn counts(nums: Vec) -> TestResult { let counts = nums.iter().counts(); for (&item, &count) in counts.iter() { + #[allow(clippy::absurd_extreme_comparisons)] if count <= 0 { return TestResult::failed(); } From 9af1fcbd80d720b09b3968ae6925e97b2407d1cc Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Thu, 7 Jul 2022 10:08:27 +0200 Subject: [PATCH 3/8] allow clippy::manual_assert in tests --- tests/quick.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/quick.rs b/tests/quick.rs index 5c73d20a9..0adcf1ad7 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -258,6 +258,7 @@ where let mut it = get_it(); for _ in 0..(counts.len() - 1) { + #[allow(clippy::manual_assert)] if it.next().is_none() { panic!("Iterator shouldn't be finished, may not be deterministic"); } From 1c50468ff7c2f3d9bb9fe30d453f3450c8165700 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Thu, 7 Jul 2022 10:15:27 +0200 Subject: [PATCH 4/8] fix clippy::redundant_else --- src/flatten_ok.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/flatten_ok.rs b/src/flatten_ok.rs index cee77c9a6..21ae1f722 100644 --- a/src/flatten_ok.rs +++ b/src/flatten_ok.rs @@ -44,11 +44,11 @@ where if let Some(inner) = &mut self.inner_front { if let Some(item) = inner.next() { return Some(Ok(item)); - } else { - // This is necessary for the iterator to implement `FusedIterator` - // with only the original iterator being fused. - self.inner_front = None; } + + // This is necessary for the iterator to implement `FusedIterator` + // with only the original iterator being fused. + self.inner_front = None; } match self.iter.next() { @@ -59,11 +59,11 @@ where if let Some(inner) = &mut self.inner_back { if let Some(item) = inner.next() { return Some(Ok(item)); - } else { - // This is necessary for the iterator to implement `FusedIterator` - // with only the original iterator being fused. - self.inner_back = None; } + + // This is necessary for the iterator to implement `FusedIterator` + // with only the original iterator being fused. + self.inner_back = None; } else { return None; } @@ -103,11 +103,11 @@ where if let Some(inner) = &mut self.inner_back { if let Some(item) = inner.next_back() { return Some(Ok(item)); - } else { - // This is necessary for the iterator to implement `FusedIterator` - // with only the original iterator being fused. - self.inner_back = None; } + + // This is necessary for the iterator to implement `FusedIterator` + // with only the original iterator being fused. + self.inner_back = None; } match self.iter.next_back() { @@ -118,11 +118,11 @@ where if let Some(inner) = &mut self.inner_front { if let Some(item) = inner.next_back() { return Some(Ok(item)); - } else { - // This is necessary for the iterator to implement `FusedIterator` - // with only the original iterator being fused. - self.inner_front = None; } + + // This is necessary for the iterator to implement `FusedIterator` + // with only the original iterator being fused. + self.inner_front = None; } else { return None; } From 6f3dbab0d1e39bd4949455454941ceb70f9bb33d Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Thu, 7 Jul 2022 10:26:25 +0200 Subject: [PATCH 5/8] fix clippy::semicolon_if_nothing_returned --- src/adaptors/mod.rs | 2 +- src/combinations_with_replacement.rs | 2 +- src/groupbylazy.rs | 4 ++-- src/lib.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/adaptors/mod.rs b/src/adaptors/mod.rs index 3c052ad04..1695bbd65 100644 --- a/src/adaptors/mod.rs +++ b/src/adaptors/mod.rs @@ -208,7 +208,7 @@ impl PutBack /// If a value is already in the put back slot, it is overwritten. #[inline] pub fn put_back(&mut self, x: I::Item) { - self.top = Some(x) + self.top = Some(x); } } diff --git a/src/combinations_with_replacement.rs b/src/combinations_with_replacement.rs index 595faafa4..0fec9671a 100644 --- a/src/combinations_with_replacement.rs +++ b/src/combinations_with_replacement.rs @@ -92,7 +92,7 @@ where // We need to update the rightmost non-max value // and all those to the right for indices_index in increment_from..self.indices.len() { - self.indices[indices_index] = increment_value + self.indices[indices_index] = increment_value; } Some(self.current()) } diff --git a/src/groupbylazy.rs b/src/groupbylazy.rs index 37371f619..bceba95e1 100644 --- a/src/groupbylazy.rs +++ b/src/groupbylazy.rs @@ -330,7 +330,7 @@ impl GroupBy /// `client`: Index of group fn drop_group(&self, client: usize) { - self.inner.borrow_mut().drop_group(client) + self.inner.borrow_mut().drop_group(client); } } @@ -482,7 +482,7 @@ impl IntoChunks /// `client`: Index of chunk fn drop_group(&self, client: usize) { - self.inner.borrow_mut().drop_group(client) + self.inner.borrow_mut().drop_group(client); } } diff --git a/src/lib.rs b/src/lib.rs index ddb11d13c..2204e8419 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1953,7 +1953,7 @@ pub trait Itertools : Iterator { where F: FnMut(Self::Item), Self: Sized, { - self.for_each(f) + self.for_each(f); } /// Combine all an iterator's elements into one element by using [`Extend`]. From c88736c61c6f1c891e2d3403f8df3701f84b64b9 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Thu, 7 Jul 2022 10:36:26 +0200 Subject: [PATCH 6/8] fix clippy::trait_duplication_in_bounds --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 2204e8419..5cca5d99f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1111,7 +1111,7 @@ pub trait Itertools : Iterator { /// ``` #[cfg(feature = "use_alloc")] fn multi_cartesian_product(self) -> MultiProduct<::IntoIter> - where Self: Iterator + Sized, + where Self: Sized, Self::Item: IntoIterator, ::IntoIter: Clone, ::Item: Clone From ed6fbda086a913a787450a642acfd4d36dc07c3b Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Thu, 7 Jul 2022 10:50:12 +0200 Subject: [PATCH 7/8] fix clippy::doc_markdown --- src/adaptors/multi_product.rs | 4 ++-- src/exactly_one_err.rs | 4 ++-- src/groupbylazy.rs | 4 ++-- src/intersperse.rs | 2 +- src/pad_tail.rs | 2 +- src/peeking_take_while.rs | 2 +- src/size_hint.rs | 16 ++++++++-------- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/adaptors/multi_product.rs b/src/adaptors/multi_product.rs index 30650eda6..0b3840698 100644 --- a/src/adaptors/multi_product.rs +++ b/src/adaptors/multi_product.rs @@ -40,7 +40,7 @@ pub fn multi_cartesian_product(iters: H) -> MultiProduct< where I: Iterator + Clone, I::Item: Clone @@ -50,7 +50,7 @@ struct MultiProductIter iter_orig: I, } -/// Holds the current state during an iteration of a MultiProduct. +/// Holds the current state during an iteration of a `MultiProduct`. #[derive(Debug)] enum MultiProductIterState { StartOfIter, diff --git a/src/exactly_one_err.rs b/src/exactly_one_err.rs index 63485c993..c54ae77ca 100644 --- a/src/exactly_one_err.rs +++ b/src/exactly_one_err.rs @@ -11,10 +11,10 @@ use crate::size_hint; /// Iterator returned for the error case of `IterTools::exactly_one()` /// This iterator yields exactly the same elements as the input iterator. /// -/// During the execution of exactly_one the iterator must be mutated. This wrapper +/// During the execution of `exactly_one` the iterator must be mutated. This wrapper /// effectively "restores" the state of the input iterator when it's handed back. /// -/// This is very similar to PutBackN except this iterator only supports 0-2 elements and does not +/// This is very similar to `PutBackN` except this iterator only supports 0-2 elements and does not /// use a `Vec`. #[derive(Clone)] pub struct ExactlyOneError diff --git a/src/groupbylazy.rs b/src/groupbylazy.rs index bceba95e1..a5a321df4 100644 --- a/src/groupbylazy.rs +++ b/src/groupbylazy.rs @@ -1,7 +1,7 @@ use std::cell::{Cell, RefCell}; use alloc::vec::{self, Vec}; -/// A trait to unify FnMut for GroupBy with the chunk key in IntoChunks +/// A trait to unify `FnMut` for `GroupBy` with the chunk key in `IntoChunks` trait KeyFunction { type Key; fn call_mut(&mut self, arg: A) -> Self::Key; @@ -18,7 +18,7 @@ impl KeyFunction for F } -/// ChunkIndex acts like the grouping key function for IntoChunks +/// `ChunkIndex` acts like the grouping key function for `IntoChunks` #[derive(Debug)] struct ChunkIndex { size: usize, diff --git a/src/intersperse.rs b/src/intersperse.rs index 9de313ee2..10a3a5389 100644 --- a/src/intersperse.rs +++ b/src/intersperse.rs @@ -55,7 +55,7 @@ pub struct IntersperseWith peek: Option, } -/// Create a new IntersperseWith iterator +/// Create a new `IntersperseWith` iterator pub fn intersperse_with(iter: I, elt: ElemF) -> IntersperseWith where I: Iterator, { diff --git a/src/pad_tail.rs b/src/pad_tail.rs index de57ee416..248a43243 100644 --- a/src/pad_tail.rs +++ b/src/pad_tail.rs @@ -23,7 +23,7 @@ where debug_fmt_fields!(PadUsing, iter, min, pos); } -/// Create a new **PadUsing** iterator. +/// Create a new `PadUsing` iterator. pub fn pad_using(iter: I, min: usize, filler: F) -> PadUsing where I: Iterator, F: FnMut(usize) -> I::Item diff --git a/src/peeking_take_while.rs b/src/peeking_take_while.rs index cd0945a52..b3a9c5ccb 100644 --- a/src/peeking_take_while.rs +++ b/src/peeking_take_while.rs @@ -90,7 +90,7 @@ where debug_fmt_fields!(PeekingTakeWhile, iter); } -/// Create a PeekingTakeWhile +/// Create a `PeekingTakeWhile` pub fn peeking_take_while(iter: &mut I, f: F) -> PeekingTakeWhile where I: Iterator, { diff --git a/src/size_hint.rs b/src/size_hint.rs index 1168ecaa3..71ea1412b 100644 --- a/src/size_hint.rs +++ b/src/size_hint.rs @@ -1,14 +1,14 @@ -//! Arithmetic on **Iterator** *.size_hint()* values. +//! Arithmetic on `Iterator.size_hint()` values. //! use std::usize; use std::cmp; use std::u32; -/// **SizeHint** is the return type of **Iterator::size_hint()**. +/// `SizeHint` is the return type of `Iterator::size_hint()`. pub type SizeHint = (usize, Option); -/// Add **SizeHint** correctly. +/// Add `SizeHint` correctly. #[inline] pub fn add(a: SizeHint, b: SizeHint) -> SizeHint { let min = a.0.saturating_add(b.0); @@ -20,7 +20,7 @@ pub fn add(a: SizeHint, b: SizeHint) -> SizeHint { (min, max) } -/// Add **x** correctly to a **SizeHint**. +/// Add `x` correctly to a `SizeHint`. #[inline] pub fn add_scalar(sh: SizeHint, x: usize) -> SizeHint { let (mut low, mut hi) = sh; @@ -29,7 +29,7 @@ pub fn add_scalar(sh: SizeHint, x: usize) -> SizeHint { (low, hi) } -/// Sbb **x** correctly to a **SizeHint**. +/// Subtract `x` correctly from a `SizeHint`. #[inline] #[allow(dead_code)] pub fn sub_scalar(sh: SizeHint, x: usize) -> SizeHint { @@ -40,7 +40,7 @@ pub fn sub_scalar(sh: SizeHint, x: usize) -> SizeHint { } -/// Multiply **SizeHint** correctly +/// Multiply `SizeHint` correctly /// /// ```ignore /// use std::usize; @@ -66,7 +66,7 @@ pub fn mul(a: SizeHint, b: SizeHint) -> SizeHint { (low, hi) } -/// Multiply **x** correctly with a **SizeHint**. +/// Multiply `x` correctly with a `SizeHint`. #[inline] pub fn mul_scalar(sh: SizeHint, x: usize) -> SizeHint { let (mut low, mut hi) = sh; @@ -75,7 +75,7 @@ pub fn mul_scalar(sh: SizeHint, x: usize) -> SizeHint { (low, hi) } -/// Raise `base` correctly by a **`SizeHint`** exponent. +/// Raise `base` correctly by a `SizeHint` exponent. #[inline] pub fn pow_scalar_base(base: usize, exp: SizeHint) -> SizeHint { let exp_low = cmp::min(exp.0, u32::MAX as usize) as u32; From 412b75be00372758a9d47e8f59235b085e96c496 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Thu, 7 Jul 2022 11:10:34 +0200 Subject: [PATCH 8/8] fix some more clippy lints --- src/lazy_buffer.rs | 20 ++++++++------------ src/permutations.rs | 7 ++----- src/tuple_impl.rs | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/lazy_buffer.rs b/src/lazy_buffer.rs index fa514ec2d..ca24062aa 100644 --- a/src/lazy_buffer.rs +++ b/src/lazy_buffer.rs @@ -28,16 +28,12 @@ where if self.done { return false; } - let next_item = self.it.next(); - match next_item { - Some(x) => { - self.buffer.push(x); - true - } - None => { - self.done = true; - false - } + if let Some(x) = self.it.next() { + self.buffer.push(x); + true + } else { + self.done = true; + false } } @@ -61,7 +57,7 @@ where { type Output = as Index>::Output; - fn index(&self, _index: J) -> &Self::Output { - self.buffer.index(_index) + fn index(&self, index: J) -> &Self::Output { + self.buffer.index(index) } } diff --git a/src/permutations.rs b/src/permutations.rs index 3080f9d5c..d03b85262 100644 --- a/src/permutations.rs +++ b/src/permutations.rs @@ -113,19 +113,15 @@ where Some(indices.map(|i| vals[i].clone()).collect()) } - PermutationState::Complete(CompleteState::Start { .. }) => None, PermutationState::Complete(CompleteState::Ongoing { ref indices, ref cycles }) => { let k = cycles.len(); - Some(indices[0..k].iter().map(|&i| vals[i].clone()).collect()) }, - PermutationState::Empty => None + PermutationState::Complete(CompleteState::Start { .. }) | PermutationState::Empty => None } } fn count(self) -> usize { - let Permutations { vals, state } = self; - fn from_complete(complete_state: CompleteState) -> usize { match complete_state.remaining() { CompleteStateRemaining::Known(count) => count, @@ -135,6 +131,7 @@ where } } + let Permutations { vals, state } = self; match state { PermutationState::StartUnknownLen { k } => { let n = vals.len() + vals.it.count(); diff --git a/src/tuple_impl.rs b/src/tuple_impl.rs index d914e0323..06b5c13cb 100644 --- a/src/tuple_impl.rs +++ b/src/tuple_impl.rs @@ -162,8 +162,8 @@ pub fn tuple_windows(mut iter: I) -> TupleWindows } TupleWindows { - last, iter, + last, } }