Skip to content

Commit c48da7b

Browse files
bors[bot]phimuemue
andauthored
Merge #454
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>
2 parents 89f3a0d + 8a562f8 commit c48da7b

13 files changed

+31
-44
lines changed

src/adaptors/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868
pub type MapOk<I, F> = MapSpecialCase<I, MapSpecialCaseFnOk<F>>;
6969

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

7474
impl<F, T, U, E> MapSpecialCaseFn<Result<T, E>> for MapSpecialCaseFnOk<F>

src/adaptors/mod.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,11 @@ impl<I, J> Iterator for InterleaveShortest<I, J>
113113

114114
#[inline]
115115
fn next(&mut self) -> Option<Self::Item> {
116-
match self.phase {
117-
false => match self.it0.next() {
118-
None => None,
119-
e => {
120-
self.phase = true;
121-
e
122-
}
123-
},
124-
true => match self.it1.next() {
125-
None => None,
126-
e => {
127-
self.phase = false;
128-
e
129-
}
130-
},
116+
let e = if self.phase { self.it1.next() } else { self.it0.next() };
117+
if e.is_some() {
118+
self.phase = !self.phase;
131119
}
120+
e
132121
}
133122

134123
#[inline]
@@ -412,7 +401,7 @@ impl<B, F, I> Iterator for Batching<I, F>
412401
/// then skipping forward *n-1* elements.
413402
///
414403
/// See [`.step()`](../trait.Itertools.html#method.step) for more information.
415-
#[deprecated(note="Use std .step_by() instead", since="0.8")]
404+
#[deprecated(note="Use std .step_by() instead", since="0.8.0")]
416405
#[allow(deprecated)]
417406
#[derive(Clone, Debug)]
418407
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]

src/adaptors/multi_product.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<I> Iterator for MultiProduct<I>
161161
}
162162

163163
fn count(self) -> usize {
164-
if self.0.len() == 0 {
164+
if self.0.is_empty() {
165165
return 0;
166166
}
167167

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

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

src/combinations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<I> Iterator for Combinations<I>
5656
return None;
5757
}
5858
self.first = false;
59-
} else if self.indices.len() == 0 {
59+
} else if self.indices.is_empty() {
6060
return None;
6161
} else {
6262
// Scan from the end, looking for an index to increment

src/concat_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ pub fn concat<I>(iterable: I) -> I::Item
1818
where I: IntoIterator,
1919
I::Item: Extend<<<I as IntoIterator>::Item as IntoIterator>::Item> + IntoIterator + Default
2020
{
21-
iterable.into_iter().fold1(|mut a, b| { a.extend(b); a }).unwrap_or_else(|| <_>::default())
21+
iterable.into_iter().fold1(|mut a, b| { a.extend(b); a }).unwrap_or_else(<_>::default)
2222
}

src/cons_tuples_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ impl<I, J> Clone for ConsTuples<I, J>
5757

5858
/// Create an iterator that maps for example iterators of
5959
/// `((A, B), C)` to `(A, B, C)`.
60-
pub fn cons_tuples<I, J>(iterable: I) -> ConsTuples<I, J>
61-
where I: Iterator<Item=J>
60+
pub fn cons_tuples<I, J>(iterable: I) -> ConsTuples<I::IntoIter, J>
61+
where I: IntoIterator<Item=J>
6262
{
6363
ConsTuples { iter: iterable.into_iter() }
6464
}

src/format.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct Format<'a, I> {
2828
inner: RefCell<Option<I>>,
2929
}
3030

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

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

6565
f.write_str(self.sep)?;
6666
}
@@ -85,7 +85,7 @@ impl<'a, I> Format<'a, I>
8585
if let Some(fst) = iter.next() {
8686
cb(&fst, f)?;
8787
for elt in iter {
88-
if self.sep.len() > 0 {
88+
if !self.sep.is_empty() {
8989
f.write_str(self.sep)?;
9090
}
9191
cb(&elt, f)?;

src/group_map.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn into_group_map<I, K, V>(iter: I) -> HashMap<K, Vec<V>>
1515
let mut lookup = HashMap::new();
1616

1717
for (key, val) in iter {
18-
lookup.entry(key).or_insert(Vec::new()).push(val);
18+
lookup.entry(key).or_insert_with(Vec::new).push(val);
1919
}
2020

2121
lookup
@@ -30,5 +30,3 @@ pub fn into_group_map_by<I, K, V>(iter: I, f: impl Fn(&V) -> K) -> HashMap<K, Ve
3030
iter.map(|v| (f(&v), v))
3131
)
3232
}
33-
34-

src/intersperse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn intersperse_with<I, ElemF>(iter: I, elt: ElemF) -> IntersperseWith<I, Ele
6262
let mut iter = iter.fuse();
6363
IntersperseWith {
6464
peek: iter.next(),
65-
iter: iter,
65+
iter,
6666
element: elt,
6767
}
6868
}

src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ pub trait Itertools : Iterator {
728728
/// let it = (0..8).step(3);
729729
/// itertools::assert_equal(it, vec![0, 3, 6]);
730730
/// ```
731-
#[deprecated(note="Use std .step_by() instead", since="0.8")]
731+
#[deprecated(note="Use std .step_by() instead", since="0.8.0")]
732732
#[allow(deprecated)]
733733
fn step(self, n: usize) -> Step<Self>
734734
where Self: Sized
@@ -751,7 +751,7 @@ pub trait Itertools : Iterator {
751751
}
752752

753753
/// See [`.map_ok()`](#method.map_ok).
754-
#[deprecated(note="Use .map_ok() instead", since="0.10")]
754+
#[deprecated(note="Use .map_ok() instead", since="0.10.0")]
755755
fn map_results<F, T, U, E>(self, f: F) -> MapOk<Self, F>
756756
where Self: Iterator<Item = Result<T, E>> + Sized,
757757
F: FnMut(T) -> U,
@@ -1651,7 +1651,7 @@ pub trait Itertools : Iterator {
16511651
///
16521652
/// itertools::assert_equal(rx.iter(), vec![1, 3, 5, 7, 9]);
16531653
/// ```
1654-
#[deprecated(note="Use .for_each() instead", since="0.8")]
1654+
#[deprecated(note="Use .for_each() instead", since="0.8.0")]
16551655
fn foreach<F>(self, f: F)
16561656
where F: FnMut(Self::Item),
16571657
Self: Sized,
@@ -1839,7 +1839,7 @@ pub trait Itertools : Iterator {
18391839
}
18401840

18411841
/// See [`.fold_ok()`](#method.fold_ok).
1842-
#[deprecated(note="Use .fold_ok() instead", since="0.10")]
1842+
#[deprecated(note="Use .fold_ok() instead", since="0.10.0")]
18431843
fn fold_results<A, E, B, F>(&mut self, start: B, f: F) -> Result<B, E>
18441844
where Self: Iterator<Item = Result<A, E>>,
18451845
F: FnMut(B, A) -> B
@@ -2099,13 +2099,13 @@ pub trait Itertools : Iterator {
20992099
/// The big difference between the computations of `result2` and `result3` is that while
21002100
/// `fold()` called the provided closure for every item of the callee iterator,
21012101
/// `fold_while()` actually stopped iterating as soon as it encountered `Fold::Done(_)`.
2102-
#[deprecated(note="Use .try_fold() instead", since="0.8")]
2102+
#[deprecated(note="Use .try_fold() instead", since="0.8.0")]
21032103
fn fold_while<B, F>(&mut self, init: B, mut f: F) -> FoldWhile<B>
21042104
where Self: Sized,
21052105
F: FnMut(B, Self::Item) -> FoldWhile<B>
21062106
{
21072107
let mut acc = init;
2108-
while let Some(item) = self.next() {
2108+
for item in self {
21092109
match f(acc, item) {
21102110
FoldWhile::Continue(res) => acc = res,
21112111
res @ FoldWhile::Done(_) => return res,

src/size_hint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub type SizeHint = (usize, Option<usize>);
1010
/// Add **SizeHint** correctly.
1111
#[inline]
1212
pub fn add(a: SizeHint, b: SizeHint) -> SizeHint {
13-
let min = a.0.checked_add(b.0).unwrap_or(usize::MAX);
13+
let min = a.0.saturating_add(b.0);
1414
let max = match (a.1, b.1) {
1515
(Some(x), Some(y)) => x.checked_add(y),
1616
_ => None,
@@ -56,7 +56,7 @@ pub fn sub_scalar(sh: SizeHint, x: usize) -> SizeHint {
5656
/// ```
5757
#[inline]
5858
pub fn mul(a: SizeHint, b: SizeHint) -> SizeHint {
59-
let low = a.0.checked_mul(b.0).unwrap_or(usize::MAX);
59+
let low = a.0.saturating_mul(b.0);
6060
let hi = match (a.1, b.1) {
6161
(Some(x), Some(y)) => x.checked_mul(y),
6262
(Some(0), None) | (None, Some(0)) => Some(0),

src/sources.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::mem;
77

88
/// See [`repeat_call`](../fn.repeat_call.html) for more information.
99
#[derive(Clone)]
10-
#[deprecated(note="Use std repeat_with() instead", since="0.8")]
10+
#[deprecated(note="Use std repeat_with() instead", since="0.8.0")]
1111
pub struct RepeatCall<F> {
1212
f: F,
1313
}
@@ -39,7 +39,7 @@ impl<F> fmt::Debug for RepeatCall<F>
3939
/// vec![1, 1, 1, 1, 1]
4040
/// );
4141
/// ```
42-
#[deprecated(note="Use std repeat_with() instead", since="0.8")]
42+
#[deprecated(note="Use std repeat_with() instead", since="0.8.0")]
4343
pub fn repeat_call<F, A>(function: F) -> RepeatCall<F>
4444
where F: FnMut() -> A
4545
{

src/tuple_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ impl<T> Iterator for TupleBuffer<T>
5757

5858
fn size_hint(&self) -> (usize, Option<usize>) {
5959
let buffer = &self.buf.as_ref()[self.cur..];
60-
let len = if buffer.len() == 0 {
60+
let len = if buffer.is_empty() {
6161
0
6262
} else {
6363
buffer.iter()
6464
.position(|x| x.is_none())
65-
.unwrap_or(buffer.len())
65+
.unwrap_or_else(|| buffer.len())
6666
};
6767
(len, Some(len))
6868
}
@@ -212,7 +212,7 @@ pub fn circular_tuple_windows<I, T>(iter: I) -> CircularTupleWindows<I, T>
212212
let iter = tuple_windows(iter.cycle()).take(len);
213213

214214
CircularTupleWindows {
215-
iter: iter,
215+
iter,
216216
phantom_data: PhantomData{}
217217
}
218218
}

0 commit comments

Comments
 (0)