Skip to content

Commit

Permalink
Merge #454
Browse files Browse the repository at this point in the history
454: Cleanup some clippy lints r=phimuemue a=phimuemue

I cleaned up some things I got from clippy. I only changed what I'd consider straightforward.

I think it would eventually be beneficial to resolve the remaining lints, so that it is easier to identify real problems spotted by clippy. Do we have a policy regarding this?

Off-topic: I would have merged this right away, but I did not want to introduce conflicts with existing PRs. Is there a way to check if my commits would introduce conflicts?

Co-authored-by: philipp <descpl@yahoo.de>
  • Loading branch information
bors[bot] and phimuemue committed Sep 4, 2020
2 parents 89f3a0d + 8a562f8 commit c48da7b
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/adaptors/map.rs
Expand Up @@ -68,7 +68,7 @@ where
pub type MapOk<I, F> = MapSpecialCase<I, MapSpecialCaseFnOk<F>>;

/// See [`MapOk`](struct.MapOk.html).
#[deprecated(note = "Use MapOk instead", since = "0.10")]
#[deprecated(note = "Use MapOk instead", since = "0.10.0")]
pub type MapResults<I, F> = MapOk<I, F>;

impl<F, T, U, E> MapSpecialCaseFn<Result<T, E>> for MapSpecialCaseFnOk<F>
Expand Down
21 changes: 5 additions & 16 deletions src/adaptors/mod.rs
Expand Up @@ -113,22 +113,11 @@ impl<I, J> Iterator for InterleaveShortest<I, J>

#[inline]
fn next(&mut self) -> Option<Self::Item> {
match self.phase {
false => match self.it0.next() {
None => None,
e => {
self.phase = true;
e
}
},
true => match self.it1.next() {
None => None,
e => {
self.phase = false;
e
}
},
let e = if self.phase { self.it1.next() } else { self.it0.next() };
if e.is_some() {
self.phase = !self.phase;
}
e
}

#[inline]
Expand Down Expand Up @@ -412,7 +401,7 @@ impl<B, F, I> Iterator for Batching<I, F>
/// then skipping forward *n-1* elements.
///
/// See [`.step()`](../trait.Itertools.html#method.step) for more information.
#[deprecated(note="Use std .step_by() instead", since="0.8")]
#[deprecated(note="Use std .step_by() instead", since="0.8.0")]
#[allow(deprecated)]
#[derive(Clone, Debug)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
Expand Down
4 changes: 2 additions & 2 deletions src/adaptors/multi_product.rs
Expand Up @@ -161,7 +161,7 @@ impl<I> Iterator for MultiProduct<I>
}

fn count(self) -> usize {
if self.0.len() == 0 {
if self.0.is_empty() {
return 0;
}

Expand All @@ -183,7 +183,7 @@ impl<I> Iterator for MultiProduct<I>

fn size_hint(&self) -> (usize, Option<usize>) {
// Not ExactSizeIterator because size may be larger than usize
if self.0.len() == 0 {
if self.0.is_empty() {
return (0, Some(0));
}

Expand Down
2 changes: 1 addition & 1 deletion src/combinations.rs
Expand Up @@ -56,7 +56,7 @@ impl<I> Iterator for Combinations<I>
return None;
}
self.first = false;
} else if self.indices.len() == 0 {
} else if self.indices.is_empty() {
return None;
} else {
// Scan from the end, looking for an index to increment
Expand Down
2 changes: 1 addition & 1 deletion src/concat_impl.rs
Expand Up @@ -18,5 +18,5 @@ pub fn concat<I>(iterable: I) -> I::Item
where I: IntoIterator,
I::Item: Extend<<<I as IntoIterator>::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_else(<_>::default)
}
4 changes: 2 additions & 2 deletions src/cons_tuples_impl.rs
Expand Up @@ -57,8 +57,8 @@ impl<I, J> Clone for ConsTuples<I, J>

/// Create an iterator that maps for example iterators of
/// `((A, B), C)` to `(A, B, C)`.
pub fn cons_tuples<I, J>(iterable: I) -> ConsTuples<I, J>
where I: Iterator<Item=J>
pub fn cons_tuples<I, J>(iterable: I) -> ConsTuples<I::IntoIter, J>
where I: IntoIterator<Item=J>
{
ConsTuples { iter: iterable.into_iter() }
}
8 changes: 4 additions & 4 deletions src/format.rs
Expand Up @@ -28,7 +28,7 @@ pub struct Format<'a, I> {
inner: RefCell<Option<I>>,
}

pub fn new_format<'a, I, F>(iter: I, separator: &'a str, f: F) -> FormatWith<'a, I, F>
pub fn new_format<I, F>(iter: I, separator: &str, f: F) -> FormatWith<'_, I, F>
where I: Iterator,
F: FnMut(I::Item, &mut dyn FnMut(&dyn fmt::Display) -> fmt::Result) -> fmt::Result
{
Expand All @@ -38,7 +38,7 @@ pub fn new_format<'a, I, F>(iter: I, separator: &'a str, f: F) -> FormatWith<'a,
}
}

pub fn new_format_default<'a, I>(iter: I, separator: &'a str) -> Format<'a, I>
pub fn new_format_default<I>(iter: I, separator: &str) -> Format<'_, I>
where I: Iterator,
{
Format {
Expand All @@ -60,7 +60,7 @@ impl<'a, I, F> fmt::Display for FormatWith<'a, I, F>
if let Some(fst) = iter.next() {
format(fst, &mut |disp: &dyn fmt::Display| disp.fmt(f))?;
for elt in iter {
if self.sep.len() > 0 {
if !self.sep.is_empty() {

f.write_str(self.sep)?;
}
Expand All @@ -85,7 +85,7 @@ impl<'a, I> Format<'a, I>
if let Some(fst) = iter.next() {
cb(&fst, f)?;
for elt in iter {
if self.sep.len() > 0 {
if !self.sep.is_empty() {
f.write_str(self.sep)?;
}
cb(&elt, f)?;
Expand Down
4 changes: 1 addition & 3 deletions src/group_map.rs
Expand Up @@ -15,7 +15,7 @@ pub fn into_group_map<I, K, V>(iter: I) -> HashMap<K, Vec<V>>
let mut lookup = HashMap::new();

for (key, val) in iter {
lookup.entry(key).or_insert(Vec::new()).push(val);
lookup.entry(key).or_insert_with(Vec::new).push(val);
}

lookup
Expand All @@ -30,5 +30,3 @@ pub fn into_group_map_by<I, K, V>(iter: I, f: impl Fn(&V) -> K) -> HashMap<K, Ve
iter.map(|v| (f(&v), v))
)
}


2 changes: 1 addition & 1 deletion src/intersperse.rs
Expand Up @@ -62,7 +62,7 @@ pub fn intersperse_with<I, ElemF>(iter: I, elt: ElemF) -> IntersperseWith<I, Ele
let mut iter = iter.fuse();
IntersperseWith {
peek: iter.next(),
iter: iter,
iter,
element: elt,
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Expand Up @@ -728,7 +728,7 @@ pub trait Itertools : Iterator {
/// let it = (0..8).step(3);
/// itertools::assert_equal(it, vec![0, 3, 6]);
/// ```
#[deprecated(note="Use std .step_by() instead", since="0.8")]
#[deprecated(note="Use std .step_by() instead", since="0.8.0")]
#[allow(deprecated)]
fn step(self, n: usize) -> Step<Self>
where Self: Sized
Expand All @@ -751,7 +751,7 @@ pub trait Itertools : Iterator {
}

/// See [`.map_ok()`](#method.map_ok).
#[deprecated(note="Use .map_ok() instead", since="0.10")]
#[deprecated(note="Use .map_ok() instead", since="0.10.0")]
fn map_results<F, T, U, E>(self, f: F) -> MapOk<Self, F>
where Self: Iterator<Item = Result<T, E>> + Sized,
F: FnMut(T) -> U,
Expand Down Expand Up @@ -1651,7 +1651,7 @@ pub trait Itertools : Iterator {
///
/// itertools::assert_equal(rx.iter(), vec![1, 3, 5, 7, 9]);
/// ```
#[deprecated(note="Use .for_each() instead", since="0.8")]
#[deprecated(note="Use .for_each() instead", since="0.8.0")]
fn foreach<F>(self, f: F)
where F: FnMut(Self::Item),
Self: Sized,
Expand Down Expand Up @@ -1839,7 +1839,7 @@ pub trait Itertools : Iterator {
}

/// See [`.fold_ok()`](#method.fold_ok).
#[deprecated(note="Use .fold_ok() instead", since="0.10")]
#[deprecated(note="Use .fold_ok() instead", since="0.10.0")]
fn fold_results<A, E, B, F>(&mut self, start: B, f: F) -> Result<B, E>
where Self: Iterator<Item = Result<A, E>>,
F: FnMut(B, A) -> B
Expand Down Expand Up @@ -2099,13 +2099,13 @@ pub trait Itertools : Iterator {
/// The big difference between the computations of `result2` and `result3` is that while
/// `fold()` called the provided closure for every item of the callee iterator,
/// `fold_while()` actually stopped iterating as soon as it encountered `Fold::Done(_)`.
#[deprecated(note="Use .try_fold() instead", since="0.8")]
#[deprecated(note="Use .try_fold() instead", since="0.8.0")]
fn fold_while<B, F>(&mut self, init: B, mut f: F) -> FoldWhile<B>
where Self: Sized,
F: FnMut(B, Self::Item) -> FoldWhile<B>
{
let mut acc = init;
while let Some(item) = self.next() {
for item in self {
match f(acc, item) {
FoldWhile::Continue(res) => acc = res,
res @ FoldWhile::Done(_) => return res,
Expand Down
4 changes: 2 additions & 2 deletions src/size_hint.rs
Expand Up @@ -10,7 +10,7 @@ pub type SizeHint = (usize, Option<usize>);
/// Add **SizeHint** correctly.
#[inline]
pub fn add(a: SizeHint, b: SizeHint) -> SizeHint {
let min = a.0.checked_add(b.0).unwrap_or(usize::MAX);
let min = a.0.saturating_add(b.0);
let max = match (a.1, b.1) {
(Some(x), Some(y)) => x.checked_add(y),
_ => None,
Expand Down Expand Up @@ -56,7 +56,7 @@ pub fn sub_scalar(sh: SizeHint, x: usize) -> SizeHint {
/// ```
#[inline]
pub fn mul(a: SizeHint, b: SizeHint) -> SizeHint {
let low = a.0.checked_mul(b.0).unwrap_or(usize::MAX);
let low = a.0.saturating_mul(b.0);
let hi = match (a.1, b.1) {
(Some(x), Some(y)) => x.checked_mul(y),
(Some(0), None) | (None, Some(0)) => Some(0),
Expand Down
4 changes: 2 additions & 2 deletions src/sources.rs
Expand Up @@ -7,7 +7,7 @@ use std::mem;

/// See [`repeat_call`](../fn.repeat_call.html) for more information.
#[derive(Clone)]
#[deprecated(note="Use std repeat_with() instead", since="0.8")]
#[deprecated(note="Use std repeat_with() instead", since="0.8.0")]
pub struct RepeatCall<F> {
f: F,
}
Expand Down Expand Up @@ -39,7 +39,7 @@ impl<F> fmt::Debug for RepeatCall<F>
/// vec![1, 1, 1, 1, 1]
/// );
/// ```
#[deprecated(note="Use std repeat_with() instead", since="0.8")]
#[deprecated(note="Use std repeat_with() instead", since="0.8.0")]
pub fn repeat_call<F, A>(function: F) -> RepeatCall<F>
where F: FnMut() -> A
{
Expand Down
6 changes: 3 additions & 3 deletions src/tuple_impl.rs
Expand Up @@ -57,12 +57,12 @@ impl<T> Iterator for TupleBuffer<T>

fn size_hint(&self) -> (usize, Option<usize>) {
let buffer = &self.buf.as_ref()[self.cur..];
let len = if buffer.len() == 0 {
let len = if buffer.is_empty() {
0
} else {
buffer.iter()
.position(|x| x.is_none())
.unwrap_or(buffer.len())
.unwrap_or_else(|| buffer.len())
};
(len, Some(len))
}
Expand Down Expand Up @@ -212,7 +212,7 @@ pub fn circular_tuple_windows<I, T>(iter: I) -> CircularTupleWindows<I, T>
let iter = tuple_windows(iter.cycle()).take(len);

CircularTupleWindows {
iter: iter,
iter,
phantom_data: PhantomData{}
}
}
Expand Down

0 comments on commit c48da7b

Please sign in to comment.