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

Address clippy lints #759

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions benches/bench1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,8 @@ fn equal(c: &mut Criterion) {
fn merge_default(c: &mut Criterion) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;
for (_, elt) in data1.iter_mut().enumerate() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason this pattern was used in the bench tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about this pattern. It definitely seems weird. Maybe due to something removed from itertools, I have no clue.
But you seem to address the same problems as the recent #740 . Sometimes in different ways.

for (x, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
}

let mut y = 0;
Expand All @@ -500,10 +498,8 @@ fn merge_default(c: &mut Criterion) {
fn merge_by_cmp(c: &mut Criterion) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;
for (_, elt) in data1.iter_mut().enumerate() {
for (x, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
}

let mut y = 0;
Expand All @@ -526,10 +522,8 @@ fn merge_by_cmp(c: &mut Criterion) {
fn merge_by_lt(c: &mut Criterion) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;
for (_, elt) in data1.iter_mut().enumerate() {
for (x, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
}

let mut y = 0;
Expand All @@ -552,10 +546,8 @@ fn merge_by_lt(c: &mut Criterion) {
fn kmerge_default(c: &mut Criterion) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;
for (_, elt) in data1.iter_mut().enumerate() {
for (x, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
}

let mut y = 0;
Expand Down Expand Up @@ -592,7 +584,7 @@ fn kmerge_tenway(c: &mut Criterion) {

let mut chunks = Vec::new();
let mut rest = &mut data[..];
while rest.len() > 0 {
while !rest.is_empty() {
let chunk_len = 1 + rng(&mut state) % 512;
let chunk_len = cmp::min(rest.len(), chunk_len as usize);
let (fst, tail) = { rest }.split_at_mut(chunk_len);
Expand Down
4 changes: 2 additions & 2 deletions benches/fold_specialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ mod specialization {
let arr = [1; 1024];

c.bench_function("internal specialized", move |b| {
b.iter(|| arr.iter().intersperse(&0).fold(0, |acc, x| acc + x))
b.iter(|| arr.iter().intersperse(&0).sum::<i32>())
});
}

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

c.bench_function("internal unspecialized", move |b| {
b.iter(|| Unspecialized(arr.iter().intersperse(&0)).fold(0, |acc, x| acc + x))
b.iter(|| Unspecialized(arr.iter().intersperse(&0)).sum::<i32>())
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/iris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::iter::repeat;
use std::num::ParseFloatError;
use std::str::FromStr;

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

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

// using Iterator::by_ref()
for (index, part) in parts.by_ref().take(4).enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ where
type Item = usize;

fn next(&mut self) -> Option<Self::Item> {
while let Some(v) = self.iter.next() {
for v in self.iter.by_ref() {
let i = self.count;
self.count = i + 1;
if (self.f)(v) {
Expand Down
6 changes: 3 additions & 3 deletions src/adaptors/multi_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ where
self.0.iter().fold(
(0, Some(0)),
|acc,
&MultiProductIter {
ref iter,
ref iter_orig,
MultiProductIter {
iter,
iter_orig,
cur: _,
}| {
let cur_size = iter.size_hint();
Expand Down
10 changes: 2 additions & 8 deletions src/either_or_both.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,13 @@ impl<A, B> EitherOrBoth<A, B> {
/// If `Left`, return true. Otherwise, return false.
/// Exclusive version of [`has_left`](EitherOrBoth::has_left).
pub fn is_left(&self) -> bool {
match *self {
Left(_) => true,
_ => false,
}
matches!(*self, Left(_))
}

/// If `Right`, return true. Otherwise, return false.
/// Exclusive version of [`has_right`](EitherOrBoth::has_right).
pub fn is_right(&self) -> bool {
match *self {
Right(_) => true,
_ => false,
}
matches!(*self, Right(_))
}

/// If `Both`, return true. Otherwise, return false.
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ pub trait Itertools: Iterator {
J: IntoIterator<Item = Self::Item>,
F: FnMut(&Self::Item, &Self::Item) -> bool,
{
merge_join::merge_by_new(self, other.into_iter(), is_first)
merge_join::merge_by_new(self, other, is_first)
}

/// Create an iterator that merges items from both this and the specified
Expand Down Expand Up @@ -4002,7 +4002,7 @@ where
(None, None) => return,
(a, b) => {
let equal = match (&a, &b) {
(&Some(ref a), &Some(ref b)) => a == b,
(Some(a), Some(b)) => a == b,
_ => false,
};
assert!(
Expand Down
4 changes: 2 additions & 2 deletions src/unique_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ where
type Item = I::Item;

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

fn next(&mut self) -> Option<Self::Item> {
while let Some(v) = self.iter.iter.next() {
for v in self.iter.iter.by_ref() {
if let Entry::Vacant(entry) = self.iter.used.entry(v) {
let elt = entry.key().clone();
entry.insert(());
Expand Down
7 changes: 3 additions & 4 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,9 +817,8 @@ quickcheck! {
quickcheck! {
fn size_put_back(a: Vec<u8>, x: Option<u8>) -> bool {
let mut it = put_back(a.into_iter());
match x {
Some(t) => it.put_back(t),
None => {}
if let Some(t) = x {
it.put_back(t)
}
correct_size_hint(it)
}
Expand Down Expand Up @@ -1320,7 +1319,7 @@ quickcheck! {
fn at_most_one_i32(a: Vec<i32>) -> TestResult {
let ret = a.iter().cloned().at_most_one();
match a.len() {
0 => TestResult::from_bool(ret.unwrap() == None),
0 => TestResult::from_bool(ret.unwrap().is_none()),
1 => TestResult::from_bool(ret.unwrap() == Some(a[0])),
_ => TestResult::from_bool(ret.unwrap_err().eq(a.iter().cloned())),
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn product2() {
assert!(prod.next() == Some(('α', 1)));
assert!(prod.next() == Some(('β', 0)));
assert!(prod.next() == Some(('β', 1)));
assert!(prod.next() == None);
assert!(prod.next().is_none());
}

#[test]
Expand Down
12 changes: 6 additions & 6 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ fn product3() {
fn interleave_shortest() {
let v0: Vec<i32> = vec![0, 2, 4];
let v1: Vec<i32> = vec![1, 3, 5, 7];
let it = v0.into_iter().interleave_shortest(v1.into_iter());
let it = v0.into_iter().interleave_shortest(v1);
assert_eq!(it.size_hint(), (6, Some(6)));
assert_eq!(it.collect_vec(), vec![0, 1, 2, 3, 4, 5]);

let v0: Vec<i32> = vec![0, 2, 4, 6, 8];
let v1: Vec<i32> = vec![1, 3, 5];
let it = v0.into_iter().interleave_shortest(v1.into_iter());
let it = v0.into_iter().interleave_shortest(v1);
assert_eq!(it.size_hint(), (7, Some(7)));
assert_eq!(it.collect_vec(), vec![0, 1, 2, 3, 4, 5, 6]);

let i0 = ::std::iter::repeat(0);
let v1: Vec<_> = vec![1, 3, 5];
let it = i0.interleave_shortest(v1.into_iter());
let it = i0.interleave_shortest(v1);
assert_eq!(it.size_hint(), (7, Some(7)));

let v0: Vec<_> = vec![0, 2, 4];
Expand Down Expand Up @@ -144,7 +144,7 @@ fn intersperse() {

let ys = [0, 1, 2, 3];
let mut it = ys[..0].iter().copied().intersperse(1);
assert!(it.next() == None);
assert!(it.next().is_none());
}

#[test]
Expand Down Expand Up @@ -415,9 +415,9 @@ fn merge_by_btree() {
let mut bt2 = BTreeMap::new();
bt2.insert("foo", 2);
bt2.insert("bar", 4);
let results = bt1.into_iter().merge_by(bt2.into_iter(), |a, b| a.0 <= b.0);
let results = bt1.into_iter().merge_by(bt2, |a, b| a.0 <= b.0);
let expected = vec![("bar", 4), ("foo", 2), ("hello", 1), ("world", 3)];
it::assert_equal(results, expected.into_iter());
it::assert_equal(results, expected);
}

#[allow(deprecated)]
Expand Down