Skip to content

Commit 265ae29

Browse files
mightyiamwarren2k
andcommitted
refactor: resolve clippy lints
Co-authored-by: warren2k <846021+warren2k@users.noreply.github.com>
1 parent 0c0bd35 commit 265ae29

13 files changed

+66
-55
lines changed

Diff for: benches/bench1.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,14 @@ fn ziplongest(c: &mut Criterion) {
397397
c.bench_function("ziplongest", move |b| {
398398
b.iter(|| {
399399
let zip = v1.iter().zip_longest(v2.iter());
400-
let sum = zip.fold(0u32, |mut acc, val| {
400+
zip.fold(0u32, |mut acc, val| {
401401
match val {
402402
EitherOrBoth::Both(x, y) => acc += x * y,
403403
EitherOrBoth::Left(x) => acc += x,
404404
EitherOrBoth::Right(y) => acc += y,
405405
}
406406
acc
407-
});
408-
sum
407+
})
409408
})
410409
});
411410
}
@@ -495,6 +494,8 @@ fn merge_default(c: &mut Criterion) {
495494
let mut data1 = vec![0; 1024];
496495
let mut data2 = vec![0; 800];
497496
let mut x = 0;
497+
498+
#[allow(clippy::explicit_counter_loop)]
498499
for (_, elt) in data1.iter_mut().enumerate() {
499500
*elt = x;
500501
x += 1;
@@ -521,6 +522,8 @@ fn merge_by_cmp(c: &mut Criterion) {
521522
let mut data1 = vec![0; 1024];
522523
let mut data2 = vec![0; 800];
523524
let mut x = 0;
525+
526+
#[allow(clippy::explicit_counter_loop)]
524527
for (_, elt) in data1.iter_mut().enumerate() {
525528
*elt = x;
526529
x += 1;
@@ -547,6 +550,8 @@ fn merge_by_lt(c: &mut Criterion) {
547550
let mut data1 = vec![0; 1024];
548551
let mut data2 = vec![0; 800];
549552
let mut x = 0;
553+
554+
#[allow(clippy::explicit_counter_loop)]
550555
for (_, elt) in data1.iter_mut().enumerate() {
551556
*elt = x;
552557
x += 1;
@@ -573,6 +578,8 @@ fn kmerge_default(c: &mut Criterion) {
573578
let mut data1 = vec![0; 1024];
574579
let mut data2 = vec![0; 800];
575580
let mut x = 0;
581+
582+
#[allow(clippy::explicit_counter_loop)]
576583
for (_, elt) in data1.iter_mut().enumerate() {
577584
*elt = x;
578585
x += 1;
@@ -612,7 +619,7 @@ fn kmerge_tenway(c: &mut Criterion) {
612619

613620
let mut chunks = Vec::new();
614621
let mut rest = &mut data[..];
615-
while rest.len() > 0 {
622+
while !rest.is_empty() {
616623
let chunk_len = 1 + rng(&mut state) % 512;
617624
let chunk_len = cmp::min(rest.len(), chunk_len as usize);
618625
let (fst, tail) = { rest }.split_at_mut(chunk_len);

Diff for: benches/extra/zipslices.rs

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ where
138138

139139
/// A helper trait to let `ZipSlices` accept both `&[T]` and `&mut [T]`.
140140
///
141+
/// # Safety
142+
///
141143
/// Unsafe trait because:
142144
///
143145
/// - Implementors must guarantee that `get_unchecked` is valid for all indices `0..len()`.

Diff for: benches/fold_specialization.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,21 @@ mod specialization {
4646
let arr = [1; 1024];
4747

4848
c.bench_function("internal specialized", move |b| {
49-
b.iter(|| arr.iter().intersperse(&0).fold(0, |acc, x| acc + x))
49+
b.iter(|| {
50+
#[allow(clippy::unnecessary_fold)]
51+
arr.iter().intersperse(&0).fold(0, |acc, x| acc + x)
52+
})
5053
});
5154
}
5255

5356
pub fn internal_unspecialized(c: &mut Criterion) {
5457
let arr = [1; 1024];
5558

5659
c.bench_function("internal unspecialized", move |b| {
57-
b.iter(|| Unspecialized(arr.iter().intersperse(&0)).fold(0, |acc, x| acc + x))
60+
b.iter(|| {
61+
#[allow(clippy::unnecessary_fold)]
62+
Unspecialized(arr.iter().intersperse(&0)).fold(0, |acc, x| acc + x)
63+
})
5864
});
5965
}
6066
}

Diff for: examples/iris.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::iter::repeat;
99
use std::num::ParseFloatError;
1010
use std::str::FromStr;
1111

12-
static DATA: &'static str = include_str!("iris.data");
12+
static DATA: &str = include_str!("iris.data");
1313

1414
#[derive(Clone, Debug)]
1515
struct Iris {
@@ -38,7 +38,7 @@ impl FromStr for Iris {
3838
name: "".into(),
3939
data: [0.; 4],
4040
};
41-
let mut parts = s.split(",").map(str::trim);
41+
let mut parts = s.split(',').map(str::trim);
4242

4343
// using Iterator::by_ref()
4444
for (index, part) in parts.by_ref().take(4).enumerate() {

Diff for: src/adaptors/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ where
10021002
type Item = usize;
10031003

10041004
fn next(&mut self) -> Option<Self::Item> {
1005-
while let Some(v) = self.iter.next() {
1005+
for v in self.iter.by_ref() {
10061006
let i = self.count;
10071007
self.count = i + 1;
10081008
if (self.f)(v) {

Diff for: src/adaptors/multi_product.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ where
220220
self.0.iter().fold(
221221
(0, Some(0)),
222222
|acc,
223-
&MultiProductIter {
224-
ref iter,
225-
ref iter_orig,
223+
MultiProductIter {
224+
iter,
225+
iter_orig,
226226
cur: _,
227227
}| {
228228
let cur_size = iter.size_hint();

Diff for: src/either_or_both.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,13 @@ impl<A, B> EitherOrBoth<A, B> {
2929
/// If `Left`, return true. Otherwise, return false.
3030
/// Exclusive version of [`has_left`](EitherOrBoth::has_left).
3131
pub fn is_left(&self) -> bool {
32-
match *self {
33-
Left(_) => true,
34-
_ => false,
35-
}
32+
matches!(*self, Left(_))
3633
}
3734

3835
/// If `Right`, return true. Otherwise, return false.
3936
/// Exclusive version of [`has_right`](EitherOrBoth::has_right).
4037
pub fn is_right(&self) -> bool {
41-
match *self {
42-
Right(_) => true,
43-
_ => false,
44-
}
38+
matches!(*self, Right(_))
4539
}
4640

4741
/// If `Both`, return true. Otherwise, return false.
@@ -500,6 +494,7 @@ impl<T> EitherOrBoth<T, T> {
500494
}
501495
}
502496

497+
#[allow(clippy::from_over_into)]
503498
impl<A, B> Into<Option<Either<A, B>>> for EitherOrBoth<A, B> {
504499
fn into(self) -> Option<Either<A, B>> {
505500
match self {

Diff for: src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ pub trait Itertools: Iterator {
10091009
J: IntoIterator<Item = Self::Item>,
10101010
F: FnMut(&Self::Item, &Self::Item) -> bool,
10111011
{
1012-
merge_join::merge_by_new(self, other.into_iter(), is_first)
1012+
merge_join::merge_by_new(self, other, is_first)
10131013
}
10141014

10151015
/// Create an iterator that merges items from both this and the specified
@@ -2048,6 +2048,7 @@ pub trait Itertools: Iterator {
20482048
/// let data : Option<usize> = None;
20492049
/// assert_eq!(data.into_iter().all_equal_value(), Err(None));
20502050
/// ```
2051+
#[allow(clippy::type_complexity)]
20512052
fn all_equal_value(&mut self) -> Result<Self::Item, Option<(Self::Item, Self::Item)>>
20522053
where
20532054
Self: Sized,
@@ -4003,7 +4004,7 @@ where
40034004
(None, None) => return,
40044005
(a, b) => {
40054006
let equal = match (&a, &b) {
4006-
(&Some(ref a), &Some(ref b)) => a == b,
4007+
(Some(a), Some(b)) => a == b,
40074008
_ => false,
40084009
};
40094010
assert!(

Diff for: src/tuple_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ where
6363
buffer
6464
.iter()
6565
.position(|x| x.is_none())
66-
.unwrap_or_else(|| buffer.len())
66+
.unwrap_or(buffer.len())
6767
};
6868
(len, Some(len))
6969
}

Diff for: src/unique_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ where
6161
type Item = I::Item;
6262

6363
fn next(&mut self) -> Option<Self::Item> {
64-
while let Some(v) = self.iter.next() {
64+
for v in self.iter.by_ref() {
6565
let key = (self.f)(&v);
6666
if self.used.insert(key, ()).is_none() {
6767
return Some(v);
@@ -115,7 +115,7 @@ where
115115
type Item = I::Item;
116116

117117
fn next(&mut self) -> Option<Self::Item> {
118-
while let Some(v) = self.iter.iter.next() {
118+
for v in self.iter.iter.by_ref() {
119119
if let Entry::Vacant(entry) = self.iter.used.entry(v) {
120120
let elt = entry.key().clone();
121121
entry.insert(());

Diff for: tests/quick.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,8 @@ quickcheck! {
819819
quickcheck! {
820820
fn size_put_back(a: Vec<u8>, x: Option<u8>) -> bool {
821821
let mut it = put_back(a.into_iter());
822-
match x {
823-
Some(t) => it.put_back(t),
824-
None => {}
822+
if let Some(t) = x {
823+
it.put_back(t)
825824
}
826825
correct_size_hint(it)
827826
}
@@ -943,7 +942,7 @@ quickcheck! {
943942
}
944943
}
945944
}
946-
cmb.next() == None
945+
cmb.next().is_none()
947946
}
948947
}
949948

@@ -1254,7 +1253,7 @@ struct Val(u32, u32);
12541253

12551254
impl PartialOrd<Val> for Val {
12561255
fn partial_cmp(&self, other: &Val) -> Option<Ordering> {
1257-
self.0.partial_cmp(&other.0)
1256+
Some(self.cmp(other))
12581257
}
12591258
}
12601259

@@ -1357,7 +1356,7 @@ quickcheck! {
13571356
fn at_most_one_i32(a: Vec<i32>) -> TestResult {
13581357
let ret = a.iter().cloned().at_most_one();
13591358
match a.len() {
1360-
0 => TestResult::from_bool(ret.unwrap() == None),
1359+
0 => TestResult::from_bool(ret.unwrap().is_none()),
13611360
1 => TestResult::from_bool(ret.unwrap() == Some(a[0])),
13621361
_ => TestResult::from_bool(ret.unwrap_err().eq(a.iter().cloned())),
13631362
}

Diff for: tests/test_core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn product2() {
2727
assert!(prod.next() == Some(('α', 1)));
2828
assert!(prod.next() == Some(('β', 0)));
2929
assert!(prod.next() == Some(('β', 1)));
30-
assert!(prod.next() == None);
30+
assert!(prod.next().is_none());
3131
}
3232

3333
#[test]

0 commit comments

Comments
 (0)