Skip to content

Commit

Permalink
Merge #624
Browse files Browse the repository at this point in the history
624: Hellow554 lints 1 r=phimuemue a=phimuemue

First batch of #618.

bors r+

Co-authored-by: Marcel Hellwig <github@cookiesoft.de>
  • Loading branch information
bors[bot] and hellow554 committed Jun 8, 2022
2 parents 28cff76 + aac4268 commit 5c11e00
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 43 deletions.
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_default()
}
4 changes: 2 additions & 2 deletions src/groupbylazy.rs
Expand Up @@ -7,7 +7,7 @@ trait KeyFunction<A> {
fn call_mut(&mut self, arg: A) -> Self::Key;
}

impl<'a, A, K, F: ?Sized> KeyFunction<A> for F
impl<A, K, F: ?Sized> KeyFunction<A> for F
where F: FnMut(A) -> K
{
type Key = K;
Expand Down Expand Up @@ -37,7 +37,7 @@ impl ChunkIndex {
}
}

impl<'a, A> KeyFunction<A> for ChunkIndex {
impl<A> KeyFunction<A> for ChunkIndex {
type Key = usize;
#[inline(always)]
fn call_mut(&mut self, _arg: A) -> Self::Key {
Expand Down
6 changes: 3 additions & 3 deletions src/grouping_map.rs
Expand Up @@ -289,7 +289,7 @@ impl<I, K, V> GroupingMap<I>
where F: FnMut(&K, &V) -> CK,
CK: Ord,
{
self.max_by(|key, v1, v2| f(key, &v1).cmp(&f(key, &v2)))
self.max_by(|key, v1, v2| f(key, v1).cmp(&f(key, v2)))
}

/// Groups elements from the `GroupingMap` source by key and finds the minimum of each group.
Expand Down Expand Up @@ -367,7 +367,7 @@ impl<I, K, V> GroupingMap<I>
where F: FnMut(&K, &V) -> CK,
CK: Ord,
{
self.min_by(|key, v1, v2| f(key, &v1).cmp(&f(key, &v2)))
self.min_by(|key, v1, v2| f(key, v1).cmp(&f(key, v2)))
}

/// Groups elements from the `GroupingMap` source by key and find the maximum and minimum of
Expand Down Expand Up @@ -480,7 +480,7 @@ impl<I, K, V> GroupingMap<I>
where F: FnMut(&K, &V) -> CK,
CK: Ord,
{
self.minmax_by(|key, v1, v2| f(key, &v1).cmp(&f(key, &v2)))
self.minmax_by(|key, v1, v2| f(key, v1).cmp(&f(key, v2)))
}

/// Groups elements from the `GroupingMap` source by key and sums them.
Expand Down
3 changes: 1 addition & 2 deletions src/intersperse.rs
Expand Up @@ -107,8 +107,7 @@ impl<I, ElemF> Iterator for IntersperseWith<I, ElemF>
self.iter.fold(accum,
|accum, x| {
let accum = f(accum, element.generate());
let accum = f(accum, x);
accum
f(accum, x)
})
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Expand Up @@ -1797,7 +1797,7 @@ pub trait Itertools : Iterator {
Some(if predicate(&first) {
first
} else {
self.find(|x| predicate(&x)).unwrap_or(first)
self.find(|x| predicate(x)).unwrap_or(first)
})
}
/// Returns `true` if the given item is present in this iterator.
Expand Down Expand Up @@ -2694,7 +2694,6 @@ pub trait Itertools : Iterator {
/// itertools::assert_equal(oldest_people_first,
/// vec!["Jill", "Jack", "Jane", "John"]);
/// ```
/// ```
#[cfg(feature = "use_alloc")]
fn sorted_by_cached_key<K, F>(self, f: F) -> VecIntoIter<Self::Item>
where
Expand Down
6 changes: 2 additions & 4 deletions src/multipeek_impl.rs
Expand Up @@ -71,10 +71,8 @@ impl<I> PeekingNext for MultiPeek<I>
if let Some(r) = self.peek() {
if !accept(r) { return None }
}
} else {
if let Some(r) = self.buf.get(0) {
if !accept(r) { return None }
}
} else if let Some(r) = self.buf.get(0) {
if !accept(r) { return None }
}
self.next()
}
Expand Down
1 change: 1 addition & 0 deletions src/ziptuple.rs
Expand Up @@ -36,6 +36,7 @@ pub struct Zip<T> {
///
/// assert_eq!(results, [0 + 3, 10 + 7, 29, 36]);
/// ```
/// [`izip!()`]: crate::izip
pub fn multizip<T, U>(t: U) -> Zip<T>
where Zip<T>: From<U>,
Zip<T>: Iterator,
Expand Down
14 changes: 6 additions & 8 deletions tests/quick.rs
Expand Up @@ -258,12 +258,12 @@ where
let mut it = get_it();

for _ in 0..(counts.len() - 1) {
if let None = it.next() {
if it.next().is_none() {
panic!("Iterator shouldn't be finished, may not be deterministic");
}
}

if let None = it.next() {
if it.next().is_none() {
break 'outer;
}

Expand Down Expand Up @@ -721,7 +721,7 @@ quickcheck! {

assert_eq!(expected_first, curr_perm);

while let Some(next_perm) = perms.next() {
for next_perm in perms {
assert!(
next_perm > curr_perm,
"next perm isn't greater-than current; next_perm={:?} curr_perm={:?} n={}",
Expand Down Expand Up @@ -943,8 +943,7 @@ quickcheck! {
fn fuzz_group_by_lazy_1(it: Iter<u8>) -> bool {
let jt = it.clone();
let groups = it.group_by(|k| *k);
let res = itertools::equal(jt, groups.into_iter().flat_map(|(_, x)| x));
res
itertools::equal(jt, groups.into_iter().flat_map(|(_, x)| x))
}
}

Expand Down Expand Up @@ -1286,7 +1285,7 @@ quickcheck! {
.map(|i| (i % modulo, i))
.into_group_map()
.into_iter()
.map(|(key, vals)| (key, vals.into_iter().fold(0u64, |acc, val| acc + val)))
.map(|(key, vals)| (key, vals.into_iter().sum()))
.collect::<HashMap<_,_>>();
assert_eq!(lookup, group_map_lookup);

Expand Down Expand Up @@ -1551,7 +1550,6 @@ quickcheck! {
}

quickcheck! {
#[test]
fn counts(nums: Vec<isize>) -> TestResult {
let counts = nums.iter().counts();
for (&item, &count) in counts.iter() {
Expand Down Expand Up @@ -1602,7 +1600,7 @@ quickcheck! {

fn is_fused<I: Iterator>(mut it: I) -> bool
{
while let Some(_) = it.next() {}
for _ in it.by_ref() {}
for _ in 0..10{
if it.next().is_some(){
return false;
Expand Down
4 changes: 2 additions & 2 deletions tests/specializations.rs
Expand Up @@ -129,7 +129,7 @@ quickcheck! {
check_results_specialized!(it, |i| {
let mut parameters_from_fold = vec![];
let fold_result = i.fold(vec![], |mut acc, v| {
parameters_from_fold.push((acc.clone(), v.clone()));
parameters_from_fold.push((acc.clone(), v));
acc.push(v);
acc
});
Expand All @@ -139,7 +139,7 @@ quickcheck! {
let mut parameters_from_all = vec![];
let first = i.next();
let all_result = i.all(|x| {
parameters_from_all.push(x.clone());
parameters_from_all.push(x);
Some(x)==first
});
(parameters_from_all, all_result)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_core.rs
Expand Up @@ -116,7 +116,7 @@ fn chain2() {
fn write_to() {
let xs = [7, 9, 8];
let mut ys = [0; 5];
let cnt = ys.iter_mut().set_from(xs.iter().map(|x| *x));
let cnt = ys.iter_mut().set_from(xs.iter().copied());
assert!(cnt == xs.len());
assert!(ys == [7, 9, 8, 0, 0]);

Expand Down
28 changes: 14 additions & 14 deletions tests/test_std.rs
Expand Up @@ -123,12 +123,12 @@ fn unique() {
#[test]
fn intersperse() {
let xs = ["a", "", "b", "c"];
let v: Vec<&str> = xs.iter().map(|x| x.clone()).intersperse(", ").collect();
let v: Vec<&str> = xs.iter().cloned().intersperse(", ").collect();
let text: String = v.concat();
assert_eq!(text, "a, , b, c".to_string());

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

Expand Down Expand Up @@ -474,7 +474,7 @@ impl<T: Clone + Send, R: Clone + Rng + SeedableRng + Send> qc::Arbitrary for Ran

// Check that taking the k smallest is the same as
// sorting then taking the k first elements
fn k_smallest_sort<I>(i: I, k: u16) -> ()
fn k_smallest_sort<I>(i: I, k: u16)
where
I: Iterator + Clone,
I::Item: Ord + Debug,
Expand Down Expand Up @@ -538,10 +538,10 @@ fn sorted_by_cached_key() {
fn test_multipeek() {
let nums = vec![1u8,2,3,4,5];

let mp = multipeek(nums.iter().map(|&x| x));
let mp = multipeek(nums.iter().copied());
assert_eq!(nums, mp.collect::<Vec<_>>());

let mut mp = multipeek(nums.iter().map(|&x| x));
let mut mp = multipeek(nums.iter().copied());
assert_eq!(mp.peek(), Some(&1));
assert_eq!(mp.next(), Some(1));
assert_eq!(mp.peek(), Some(&2));
Expand Down Expand Up @@ -579,7 +579,7 @@ fn test_multipeek_peeking_next() {
use crate::it::PeekingNext;
let nums = vec![1u8,2,3,4,5,6,7];

let mut mp = multipeek(nums.iter().map(|&x| x));
let mut mp = multipeek(nums.iter().copied());
assert_eq!(mp.peeking_next(|&x| x != 0), Some(1));
assert_eq!(mp.next(), Some(2));
assert_eq!(mp.peek(), Some(&3));
Expand All @@ -604,10 +604,10 @@ fn test_multipeek_peeking_next() {
fn test_peek_nth() {
let nums = vec![1u8,2,3,4,5];

let iter = peek_nth(nums.iter().map(|&x| x));
let iter = peek_nth(nums.iter().copied());
assert_eq!(nums, iter.collect::<Vec<_>>());

let mut iter = peek_nth(nums.iter().map(|&x| x));
let mut iter = peek_nth(nums.iter().copied());

assert_eq!(iter.peek_nth(0), Some(&1));
assert_eq!(iter.peek_nth(0), Some(&1));
Expand Down Expand Up @@ -638,7 +638,7 @@ fn test_peek_nth() {
fn test_peek_nth_peeking_next() {
use it::PeekingNext;
let nums = vec![1u8,2,3,4,5,6,7];
let mut iter = peek_nth(nums.iter().map(|&x| x));
let mut iter = peek_nth(nums.iter().copied());

assert_eq!(iter.peeking_next(|&x| x != 0), Some(1));
assert_eq!(iter.next(), Some(2));
Expand Down Expand Up @@ -694,7 +694,7 @@ fn group_by() {
}
}

let toupper = |ch: &char| ch.to_uppercase().nth(0).unwrap();
let toupper = |ch: &char| ch.to_uppercase().next().unwrap();

// try all possible orderings
for indices in permutohedron::Heap::new(&mut [0, 1, 2, 3]) {
Expand Down Expand Up @@ -1091,9 +1091,9 @@ fn format() {
let t2 = format!("{:?}", data.iter().format("--"));
assert_eq!(t2, ans2);

let dataf = [1.1, 2.71828, -22.];
let dataf = [1.1, 5.71828, -22.];
let t3 = format!("{:.2e}", dataf.iter().format(", "));
assert_eq!(t3, "1.10e0, 2.72e0, -2.20e1");
assert_eq!(t3, "1.10e0, 5.72e0, -2.20e1");
}

#[test]
Expand All @@ -1110,7 +1110,7 @@ fn fold_while() {
let vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let sum = vec.into_iter().fold_while(0, |acc, item| {
iterations += 1;
let new_sum = acc.clone() + item;
let new_sum = acc + item;
if new_sum <= 20 {
FoldWhile::Continue(new_sum)
} else {
Expand Down Expand Up @@ -1143,7 +1143,7 @@ fn tree_fold1() {
"0 1 x 2 3 x x 4 5 x 6 7 x x x 8 9 x 10 11 x x 12 13 x 14 15 x x x x",
];
for (i, &s) in x.iter().enumerate() {
let expected = if s == "" { None } else { Some(s.to_string()) };
let expected = if s.is_empty() { None } else { Some(s.to_string()) };
let num_strings = (0..i).map(|x| x.to_string());
let actual = num_strings.tree_fold1(|a, b| format!("{} {} x", a, b));
assert_eq!(actual, expected);
Expand Down
8 changes: 4 additions & 4 deletions tests/zip.rs
Expand Up @@ -29,8 +29,8 @@ fn test_zip_longest_size_hint() {
fn test_double_ended_zip_longest() {
let xs = [1, 2, 3, 4, 5, 6];
let ys = [1, 2, 3, 7];
let a = xs.iter().map(|&x| x);
let b = ys.iter().map(|&x| x);
let a = xs.iter().copied();
let b = ys.iter().copied();
let mut it = a.zip_longest(b);
assert_eq!(it.next(), Some(Both(1, 1)));
assert_eq!(it.next(), Some(Both(2, 2)));
Expand All @@ -45,8 +45,8 @@ fn test_double_ended_zip_longest() {
fn test_double_ended_zip() {
let xs = [1, 2, 3, 4, 5, 6];
let ys = [1, 2, 3, 7];
let a = xs.iter().map(|&x| x);
let b = ys.iter().map(|&x| x);
let a = xs.iter().copied();
let b = ys.iter().copied();
let mut it = multizip((a, b));
assert_eq!(it.next_back(), Some((4, 7)));
assert_eq!(it.next_back(), Some((3, 3)));
Expand Down

0 comments on commit 5c11e00

Please sign in to comment.