Skip to content

Commit

Permalink
build: resolve warnings
Browse files Browse the repository at this point in the history
Co-authored-by: warren2k <846021+warren2k@users.noreply.github.com>
  • Loading branch information
mightyiam and warren2k committed Sep 9, 2023
1 parent 9b1f818 commit 7c2a5df
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 19 deletions.
12 changes: 8 additions & 4 deletions benches/fold_specialization.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#[path = "../wrappers.rs"]
mod wrappers;

use wrappers::Ext;

use criterion::{criterion_group, criterion_main, Criterion};
use itertools::Itertools;

struct Unspecialized<I>(I);

Expand Down Expand Up @@ -32,7 +36,7 @@ mod specialization {
c.bench_function("external", move |b| {
b.iter(|| {
let mut sum = 0;
for &x in arr.iter().intersperse(&0) {
for &x in arr.iter().intersperse_wrap(&0) {
sum += x;
}
sum
Expand All @@ -46,7 +50,7 @@ mod specialization {

c.bench_function("internal specialized", move |b| {
b.iter(|| {
arr.iter().intersperse(&0).fold(0, |acc, x| acc + x)
arr.iter().intersperse_wrap(&0).fold(0, |acc, x| acc + x)
})
});
}
Expand All @@ -57,7 +61,7 @@ mod specialization {

c.bench_function("internal unspecialized", move |b| {
b.iter(|| {
Unspecialized(arr.iter().intersperse(&0)).fold(0, |acc, x| acc + x)
Unspecialized(arr.iter().intersperse_wrap(&0)).fold(0, |acc, x| acc + x)
})
});
}
Expand Down
12 changes: 8 additions & 4 deletions benches/tree_fold1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#[path = "../wrappers.rs"]
mod wrappers;

use criterion::{criterion_group, criterion_main, Criterion};
use itertools::{Itertools, cloned};
use wrappers::Ext;

trait IterEx : Iterator {
// Another efficient implementation against which to compare,
Expand All @@ -18,7 +22,7 @@ trait IterEx : Iterator {
}
stack.push(x);
});
stack.into_iter().fold1(f)
stack.into_iter().fold1_wrap(f)
}
}
impl<T:Iterator> IterEx for T {}
Expand Down Expand Up @@ -79,7 +83,7 @@ macro_rules! def_benchs {

def_benchs!{
10_000,
fold1,
fold1_wrap,
fold1_10k,
}

Expand All @@ -97,7 +101,7 @@ def_benchs!{

def_benchs!{
100,
fold1,
fold1_wrap,
fold1_100,
}

Expand All @@ -115,7 +119,7 @@ def_benchs!{

def_benchs!{
8,
fold1,
fold1_wrap,
fold1_08,
}

Expand Down
18 changes: 12 additions & 6 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//!
//! In particular we test the tedious size_hint and exact size correctness.

#[path = "../wrappers.rs"]
mod wrappers;

use quickcheck as qc;
use std::default::Default;
use std::num::Wrapping;
Expand All @@ -24,14 +27,17 @@ use itertools::free::{
put_back,
put_back_n,
rciter,
zip,
zip_eq,
};

use wrappers::free::zip;

use rand::Rng;
use rand::seq::SliceRandom;
use quickcheck::TestResult;

use crate::wrappers::Ext;

/// Trait for size hint modifier types
trait HintKind: Copy + Send + qc::Arbitrary {
fn loosen_bounds(&self, org_hint: (usize, Option<usize>)) -> (usize, Option<usize>);
Expand Down Expand Up @@ -635,12 +641,12 @@ quickcheck! {
exact_size_for_this(a.iter().interleave_shortest(&b))
}
fn size_intersperse(a: Iter<i16>, x: i16) -> bool {
correct_size_hint(a.intersperse(x))
correct_size_hint(a.intersperse_wrap(x))
}
fn equal_intersperse(a: Vec<i32>, x: i32) -> bool {
let mut inter = false;
let mut i = 0;
for elt in a.iter().cloned().intersperse(x) {
for elt in a.iter().cloned().intersperse_wrap(x) {
if inter {
if elt != x { return false }
} else {
Expand Down Expand Up @@ -1243,8 +1249,8 @@ quickcheck! {
return TestResult::discard();
}

let min = cloned(&a).fold1(f64::min);
let max = cloned(&a).fold1(f64::max);
let min = cloned(&a).fold1_wrap(f64::min);
let max = cloned(&a).fold1_wrap(f64::max);

let minmax = cloned(&a).minmax();
let expected = match a.len() {
Expand Down Expand Up @@ -1405,7 +1411,7 @@ quickcheck! {
.map(|i| (i % modulo, i))
.into_group_map()
.into_iter()
.map(|(key, vals)| (key, vals.into_iter().fold1(|acc, val| acc + val).unwrap()))
.map(|(key, vals)| (key, vals.into_iter().fold1_wrap(|acc, val| acc + val).unwrap()))
.collect::<HashMap<_,_>>();
assert_eq!(lookup, group_map_lookup);

Expand Down
7 changes: 6 additions & 1 deletion tests/specializations.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#[path = "../wrappers.rs"]
mod wrappers;

use itertools::Itertools;
use std::fmt::Debug;
use quickcheck::quickcheck;

use crate::wrappers::Ext;

struct Unspecialized<I>(I);
impl<I> Iterator for Unspecialized<I>
where
Expand Down Expand Up @@ -74,7 +79,7 @@ fn test_specializations<IterItem, Iter>(

quickcheck! {
fn intersperse(v: Vec<u8>) -> () {
test_specializations(&v.into_iter().intersperse(0));
test_specializations(&v.into_iter().intersperse_wrap(0));
}
}

Expand Down
6 changes: 5 additions & 1 deletion tests/test_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
//! except according to those terms.
#![no_std]

#[path = "../wrappers.rs"]
mod wrappers;

use core::iter;
use itertools as it;
use crate::it::Itertools;
Expand All @@ -16,6 +19,7 @@ use crate::it::free::put_back;
use crate::it::iproduct;
use crate::it::izip;
use crate::it::chain;
use crate::wrappers::Ext;

#[test]
fn product2() {
Expand Down Expand Up @@ -278,7 +282,7 @@ fn part() {
#[test]
fn tree_fold1() {
for i in 0..100 {
assert_eq!((0..i).tree_fold1(|x, y| x + y), (0..i).fold1(|x, y| x + y));
assert_eq!((0..i).tree_fold1(|x, y| x + y), (0..i).fold1_wrap(|x, y| x + y));
}
}

Expand Down
9 changes: 6 additions & 3 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#[path = "../wrappers.rs"]
mod wrappers;

use quickcheck as qc;
use rand::{distributions::{Distribution, Standard}, Rng, SeedableRng, rngs::StdRng};
use rand::{seq::SliceRandom, thread_rng};
use std::{cmp::min, fmt::Debug, marker::PhantomData};
use itertools as it;
use crate::it::Itertools;
use crate::{it::Itertools, wrappers::Ext};
use crate::it::ExactlyOneError;
use crate::it::multizip;
use crate::it::multipeek;
Expand Down Expand Up @@ -121,12 +124,12 @@ fn unique() {
#[test]
fn intersperse() {
let xs = ["a", "", "b", "c"];
let v: Vec<&str> = xs.iter().cloned().intersperse(", ").collect();
let v: Vec<&str> = xs.iter().cloned().intersperse_wrap(", ").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().copied().intersperse(1);
let mut it = ys[..0].iter().copied().intersperse_wrap(1);
assert!(it.next() == None);
}

Expand Down
38 changes: 38 additions & 0 deletions wrappers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! This module helps suppress two kinds of warnings: `deprecated` and `unstable_name_collisions`.
//! New items are created that are noop-wrappers of the original items.
//! The items' original paths are preserved.

use itertools::Itertools;

pub mod free {
// it seems the compiler is not able to discern that this is used
#[allow(dead_code)]
pub fn zip<I, J>(i: I, j: J) -> core::iter::Zip<I::IntoIter, J::IntoIter>
where I: IntoIterator,
J: IntoIterator
{
#[allow(deprecated)]
itertools::free::zip(i, j)
}
}

pub trait Ext: Itertools {
fn intersperse_wrap(self, element: Self::Item) -> itertools::Intersperse<Self>
where
Self: Sized,
Self::Item: Clone,
{
<Self as Itertools>::intersperse(self, element)
}

fn fold1_wrap<F>(self, f: F) -> Option<Self::Item>
where F: FnMut(Self::Item, Self::Item) -> Self::Item,
Self: Sized,
{
#[allow(deprecated)]
<Self as Itertools>::fold1(self, f)
}
}

impl<T: Itertools> Ext for T {}

0 comments on commit 7c2a5df

Please sign in to comment.