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 16, 2023
1 parent e41823f commit 129259e
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 18 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 @@ -44,15 +48,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_wrap(&0).fold(0, |acc, x| acc + x))
});
}

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_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::{cloned, Itertools};
use wrappers::Ext;

trait IterEx: Iterator {
// Another efficient implementation against which to compare,
Expand All @@ -19,7 +23,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 @@ -83,7 +87,7 @@ macro_rules! def_benchs {

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

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

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

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

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

Expand Down
1 change: 1 addition & 0 deletions src/size_hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn add_scalar(sh: SizeHint, x: usize) -> SizeHint {
}

/// Subtract `x` correctly from a `SizeHint`.
#[cfg(feature = "use_alloc")]
#[inline]
pub fn sub_scalar(sh: SizeHint, x: usize) -> SizeHint {
let (mut low, mut hi) = sh;
Expand Down
18 changes: 12 additions & 6 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
//!
//! In particular we test the tedious size_hint and exact size correctness.

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

use itertools::free::{
cloned, enumerate, multipeek, peek_nth, put_back, put_back_n, rciter, zip, zip_eq,
cloned, enumerate, multipeek, peek_nth, put_back, put_back_n, rciter, zip_eq,
};
use itertools::Itertools;
use itertools::{iproduct, izip, multizip, EitherOrBoth};
Expand All @@ -14,11 +17,14 @@ use std::collections::{HashMap, HashSet};
use std::default::Default;
use std::num::Wrapping;
use std::ops::Range;
use wrappers::free::zip;

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

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 @@ -641,12 +647,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 @@ -1249,8 +1255,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 @@ -1411,7 +1417,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 quickcheck::quickcheck;
use std::fmt::Debug;

use crate::wrappers::Ext;

struct Unspecialized<I>(I);
impl<I> Iterator for Unspecialized<I>
where
Expand Down Expand Up @@ -73,7 +78,7 @@ where

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

Expand Down
9 changes: 8 additions & 1 deletion tests/test_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! option. This file may not be copied, modified, or distributed
//! except according to those terms.
#![no_std]
#[path = "../wrappers.rs"]
mod wrappers;

use crate::it::chain;
use crate::it::free::put_back;
Expand All @@ -17,6 +19,8 @@ use crate::it::Itertools;
use core::iter;
use itertools as it;

use crate::wrappers::Ext;

#[test]
fn product2() {
let s = "αβ";
Expand Down Expand Up @@ -280,7 +284,10 @@ 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: 7 additions & 2 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[path = "../wrappers.rs"]
mod wrappers;

use crate::it::cloned;
use crate::it::free::put_back_n;
use crate::it::free::rciter;
Expand All @@ -9,6 +12,8 @@ use crate::it::peek_nth;
use crate::it::ExactlyOneError;
use crate::it::FoldWhile;
use crate::it::Itertools;
use crate::wrappers::Ext;

use itertools as it;
use quickcheck as qc;
use rand::{
Expand Down Expand Up @@ -138,12 +143,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 129259e

Please sign in to comment.