Skip to content

Commit 5e2377b

Browse files
mightyiamwarren2k
andcommitted
refactor: resolve clippy lints
Co-authored-by: warren2k <[email protected]>
1 parent 7473afb commit 5e2377b

15 files changed

+73
-60
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
- uses: actions/checkout@v4
2525
- uses: dtolnay/rust-toolchain@stable
2626
with:
27-
components: ${{ matrix.rust == 'stable' && 'clippy' || '' }}
28-
- run: RUSTFLAGS="--deny warnings" cargo ${{ matrix.rust == 'stable' && 'clippy' || 'check' }} ${{ matrix.features }}
27+
components: clippy
28+
- run: RUSTFLAGS="--deny warnings" cargo clippy ${{ matrix.features }}
2929

3030
msrv:
3131
runs-on: ubuntu-latest

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ categories = ["algorithms", "rust-patterns"]
1515

1616
edition = "2018"
1717

18+
# When bumping, please resolve all `#[allow(clippy::*)]` that are newly resolvable.
1819
rust-version = "1.43.1"
1920

2021
[lib]

benches/bench1.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ fn merge_default(c: &mut Criterion) {
475475
let mut data1 = vec![0; 1024];
476476
let mut data2 = vec![0; 800];
477477
let mut x = 0;
478+
479+
#[allow(clippy::explicit_counter_loop, clippy::unused_enumerate_index)]
478480
for (_, elt) in data1.iter_mut().enumerate() {
479481
*elt = x;
480482
x += 1;
@@ -501,6 +503,8 @@ fn merge_by_cmp(c: &mut Criterion) {
501503
let mut data1 = vec![0; 1024];
502504
let mut data2 = vec![0; 800];
503505
let mut x = 0;
506+
507+
#[allow(clippy::explicit_counter_loop, clippy::unused_enumerate_index)]
504508
for (_, elt) in data1.iter_mut().enumerate() {
505509
*elt = x;
506510
x += 1;
@@ -527,6 +531,8 @@ fn merge_by_lt(c: &mut Criterion) {
527531
let mut data1 = vec![0; 1024];
528532
let mut data2 = vec![0; 800];
529533
let mut x = 0;
534+
535+
#[allow(clippy::explicit_counter_loop, clippy::unused_enumerate_index)]
530536
for (_, elt) in data1.iter_mut().enumerate() {
531537
*elt = x;
532538
x += 1;
@@ -553,6 +559,8 @@ fn kmerge_default(c: &mut Criterion) {
553559
let mut data1 = vec![0; 1024];
554560
let mut data2 = vec![0; 800];
555561
let mut x = 0;
562+
563+
#[allow(clippy::explicit_counter_loop, clippy::unused_enumerate_index)]
556564
for (_, elt) in data1.iter_mut().enumerate() {
557565
*elt = x;
558566
x += 1;
@@ -592,7 +600,7 @@ fn kmerge_tenway(c: &mut Criterion) {
592600

593601
let mut chunks = Vec::new();
594602
let mut rest = &mut data[..];
595-
while rest.len() > 0 {
603+
while !rest.is_empty() {
596604
let chunk_len = 1 + rng(&mut state) % 512;
597605
let chunk_len = cmp::min(rest.len(), chunk_len as usize);
598606
let (fst, tail) = { rest }.split_at_mut(chunk_len);

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()`.

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
}

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() {

src/adaptors/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -607,11 +607,11 @@ where
607607
Some(item) => Ok(f(acc, item)),
608608
None => Err(acc),
609609
});
610-
let res = match res {
610+
611+
match res {
611612
Ok(val) => val,
612613
Err(val) => val,
613-
};
614-
res
614+
}
615615
}
616616
}
617617

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();

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 {

src/lib.rs

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

10141014
/// Create an iterator that merges items from both this and the specified
@@ -2047,6 +2047,7 @@ pub trait Itertools: Iterator {
20472047
/// let data : Option<usize> = None;
20482048
/// assert_eq!(data.into_iter().all_equal_value(), Err(None));
20492049
/// ```
2050+
#[allow(clippy::type_complexity)]
20502051
fn all_equal_value(&mut self) -> Result<Self::Item, Option<(Self::Item, Self::Item)>>
20512052
where
20522053
Self: Sized,
@@ -4013,7 +4014,7 @@ where
40134014
(None, None) => return,
40144015
(a, b) => {
40154016
let equal = match (&a, &b) {
4016-
(&Some(ref a), &Some(ref b)) => a == b,
4017+
(Some(a), Some(b)) => a == b,
40174018
_ => false,
40184019
};
40194020
assert!(

src/multipeek_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ where
7979
return None;
8080
}
8181
}
82-
} else if let Some(r) = self.buf.get(0) {
82+
} else if let Some(r) = self.buf.front() {
8383
if !accept(r) {
8484
return None;
8585
}

src/tuple_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ where
6262
buffer
6363
.iter()
6464
.position(|x| x.is_none())
65-
.unwrap_or_else(|| buffer.len())
65+
.unwrap_or(buffer.len())
6666
};
6767
(len, Some(len))
6868
}

tests/quick.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -779,11 +779,11 @@ quickcheck! {
779779

780780
fn peek_nth_mut_replace(a: Vec<u16>, b: Vec<u16>) -> () {
781781
let mut it = peek_nth(a.iter());
782-
for i in 0..a.len().min(b.len()) {
783-
*it.peek_nth_mut(i).unwrap() = &b[i];
782+
for (i, m) in b.iter().enumerate().take(a.len().min(b.len())) {
783+
*it.peek_nth_mut(i).unwrap() = m;
784784
}
785-
for i in 0..a.len() {
786-
assert_eq!(it.next().unwrap(), b.get(i).unwrap_or(&a[i]));
785+
for (i, m) in a.iter().enumerate() {
786+
assert_eq!(it.next().unwrap(), b.get(i).unwrap_or(m));
787787
}
788788
assert_eq!(it.next(), None);
789789
assert_eq!(it.next(), None);
@@ -875,9 +875,8 @@ quickcheck! {
875875
quickcheck! {
876876
fn size_put_back(a: Vec<u8>, x: Option<u8>) -> bool {
877877
let mut it = put_back(a.into_iter());
878-
match x {
879-
Some(t) => it.put_back(t),
880-
None => {}
878+
if let Some(t) = x {
879+
it.put_back(t)
881880
}
882881
correct_size_hint(it)
883882
}
@@ -999,7 +998,7 @@ quickcheck! {
999998
}
1000999
}
10011000
}
1002-
cmb.next() == None
1001+
cmb.next().is_none()
10031002
}
10041003
}
10051004

@@ -1310,7 +1309,7 @@ struct Val(u32, u32);
13101309

13111310
impl PartialOrd<Val> for Val {
13121311
fn partial_cmp(&self, other: &Val) -> Option<Ordering> {
1313-
self.0.partial_cmp(&other.0)
1312+
Some(self.cmp(other))
13141313
}
13151314
}
13161315

@@ -1413,7 +1412,7 @@ quickcheck! {
14131412
fn at_most_one_i32(a: Vec<i32>) -> TestResult {
14141413
let ret = a.iter().cloned().at_most_one();
14151414
match a.len() {
1416-
0 => TestResult::from_bool(ret.unwrap() == None),
1415+
0 => TestResult::from_bool(ret.unwrap().is_none()),
14171416
1 => TestResult::from_bool(ret.unwrap() == Some(a[0])),
14181417
_ => TestResult::from_bool(ret.unwrap_err().eq(a.iter().cloned())),
14191418
}

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)