Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hellow554 lints 3 #630

Merged
merged 8 commits into from Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions clippy.toml
@@ -0,0 +1 @@
msrv = "1.36.0"
2 changes: 1 addition & 1 deletion src/adaptors/mod.rs
Expand Up @@ -208,7 +208,7 @@ impl<I> PutBack<I>
/// 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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/adaptors/multi_product.rs
Expand Up @@ -40,7 +40,7 @@ pub fn multi_cartesian_product<H>(iters: H) -> MultiProduct<<H::Item as IntoIter
}

#[derive(Clone, Debug)]
/// Holds the state of a single iterator within a MultiProduct.
/// Holds the state of a single iterator within a `MultiProduct`.
struct MultiProductIter<I>
where I: Iterator + Clone,
I::Item: Clone
Expand All @@ -50,7 +50,7 @@ struct MultiProductIter<I>
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,
Expand Down
2 changes: 1 addition & 1 deletion src/combinations_with_replacement.rs
Expand Up @@ -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())
}
Expand Down
4 changes: 2 additions & 2 deletions src/exactly_one_err.rs
Expand Up @@ -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<I>
Expand Down
32 changes: 16 additions & 16 deletions src/flatten_ok.rs
Expand Up @@ -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() {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions 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<A> {
type Key;
fn call_mut(&mut self, arg: A) -> Self::Key;
Expand All @@ -18,7 +18,7 @@ impl<A, K, F: ?Sized> KeyFunction<A> 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,
Expand Down Expand Up @@ -330,7 +330,7 @@ impl<K, I, F> GroupBy<K, I, F>

/// `client`: Index of group
fn drop_group(&self, client: usize) {
self.inner.borrow_mut().drop_group(client)
self.inner.borrow_mut().drop_group(client);
}
}

Expand Down Expand Up @@ -482,7 +482,7 @@ impl<I> IntoChunks<I>

/// `client`: Index of chunk
fn drop_group(&self, client: usize) {
self.inner.borrow_mut().drop_group(client)
self.inner.borrow_mut().drop_group(client);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/intersperse.rs
Expand Up @@ -55,7 +55,7 @@ pub struct IntersperseWith<I, ElemF>
peek: Option<I::Item>,
}

/// Create a new IntersperseWith iterator
/// Create a new `IntersperseWith` iterator
pub fn intersperse_with<I, ElemF>(iter: I, elt: ElemF) -> IntersperseWith<I, ElemF>
where I: Iterator,
{
Expand Down
20 changes: 8 additions & 12 deletions src/lazy_buffer.rs
Expand Up @@ -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
}
}

Expand All @@ -61,7 +57,7 @@ where
{
type Output = <Vec<I::Item> as Index<J>>::Output;

fn index(&self, _index: J) -> &Self::Output {
self.buffer.index(_index)
fn index(&self, index: J) -> &Self::Output {
self.buffer.index(index)
}
}
4 changes: 2 additions & 2 deletions src/lib.rs
Expand Up @@ -1111,7 +1111,7 @@ pub trait Itertools : Iterator {
/// ```
#[cfg(feature = "use_alloc")]
fn multi_cartesian_product(self) -> MultiProduct<<Self::Item as IntoIterator>::IntoIter>
where Self: Iterator + Sized,
where Self: Sized,
Self::Item: IntoIterator,
<Self::Item as IntoIterator>::IntoIter: Clone,
<Self::Item as IntoIterator>::Item: Clone
Expand Down Expand Up @@ -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`].
Expand Down
2 changes: 1 addition & 1 deletion src/pad_tail.rs
Expand Up @@ -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<I, F>(iter: I, min: usize, filler: F) -> PadUsing<I, F>
where I: Iterator,
F: FnMut(usize) -> I::Item
Expand Down
2 changes: 1 addition & 1 deletion src/peeking_take_while.rs
Expand Up @@ -90,7 +90,7 @@ where
debug_fmt_fields!(PeekingTakeWhile, iter);
}

/// Create a PeekingTakeWhile
/// Create a `PeekingTakeWhile`
pub fn peeking_take_while<I, F>(iter: &mut I, f: F) -> PeekingTakeWhile<I, F>
where I: Iterator,
{
Expand Down
7 changes: 2 additions & 5 deletions src/permutations.rs
Expand Up @@ -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,
Expand All @@ -135,6 +131,7 @@ where
}
}

let Permutations { vals, state } = self;
match state {
PermutationState::StartUnknownLen { k } => {
let n = vals.len() + vals.it.count();
Expand Down
16 changes: 8 additions & 8 deletions 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<usize>);

/// Add **SizeHint** correctly.
/// Add `SizeHint` correctly.
#[inline]
pub fn add(a: SizeHint, b: SizeHint) -> SizeHint {
let min = a.0.saturating_add(b.0);
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -40,7 +40,7 @@ pub fn sub_scalar(sh: SizeHint, x: usize) -> SizeHint {
}


/// Multiply **SizeHint** correctly
/// Multiply `SizeHint` correctly
///
/// ```ignore
/// use std::usize;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/tuple_impl.rs
Expand Up @@ -162,8 +162,8 @@ pub fn tuple_windows<I, T>(mut iter: I) -> TupleWindows<I, T>
}

TupleWindows {
last,
iter,
last,
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/quick.rs
Expand Up @@ -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");
}
Expand Down Expand Up @@ -1548,6 +1549,7 @@ quickcheck! {
fn counts(nums: Vec<isize>) -> TestResult {
let counts = nums.iter().counts();
for (&item, &count) in counts.iter() {
#[allow(clippy::absurd_extreme_comparisons)]
if count <= 0 {
return TestResult::failed();
}
Expand Down