Skip to content

Commit d3adf4c

Browse files
mightyiamwarren2k
andcommitted
build: resolve warnings
Co-authored-by: warren2k <[email protected]>
1 parent 9b1f818 commit d3adf4c

File tree

8 files changed

+84
-19
lines changed

8 files changed

+84
-19
lines changed

benches/fold_specialization.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
#[path = "../wrappers.rs"]
2+
mod wrappers;
3+
4+
use wrappers::Ext;
5+
16
use criterion::{criterion_group, criterion_main, Criterion};
2-
use itertools::Itertools;
37

48
struct Unspecialized<I>(I);
59

@@ -32,7 +36,7 @@ mod specialization {
3236
c.bench_function("external", move |b| {
3337
b.iter(|| {
3438
let mut sum = 0;
35-
for &x in arr.iter().intersperse(&0) {
39+
for &x in arr.iter().intersperse_wrap(&0) {
3640
sum += x;
3741
}
3842
sum
@@ -46,7 +50,7 @@ mod specialization {
4650

4751
c.bench_function("internal specialized", move |b| {
4852
b.iter(|| {
49-
arr.iter().intersperse(&0).fold(0, |acc, x| acc + x)
53+
arr.iter().intersperse_wrap(&0).fold(0, |acc, x| acc + x)
5054
})
5155
});
5256
}
@@ -57,7 +61,7 @@ mod specialization {
5761

5862
c.bench_function("internal unspecialized", move |b| {
5963
b.iter(|| {
60-
Unspecialized(arr.iter().intersperse(&0)).fold(0, |acc, x| acc + x)
64+
Unspecialized(arr.iter().intersperse_wrap(&0)).fold(0, |acc, x| acc + x)
6165
})
6266
});
6367
}

benches/tree_fold1.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
#[path = "../wrappers.rs"]
2+
mod wrappers;
3+
14
use criterion::{criterion_group, criterion_main, Criterion};
25
use itertools::{Itertools, cloned};
6+
use wrappers::Ext;
37

48
trait IterEx : Iterator {
59
// Another efficient implementation against which to compare,
@@ -18,7 +22,7 @@ trait IterEx : Iterator {
1822
}
1923
stack.push(x);
2024
});
21-
stack.into_iter().fold1(f)
25+
stack.into_iter().fold1_wrap(f)
2226
}
2327
}
2428
impl<T:Iterator> IterEx for T {}
@@ -79,7 +83,7 @@ macro_rules! def_benchs {
7983

8084
def_benchs!{
8185
10_000,
82-
fold1,
86+
fold1_wrap,
8387
fold1_10k,
8488
}
8589

@@ -97,7 +101,7 @@ def_benchs!{
97101

98102
def_benchs!{
99103
100,
100-
fold1,
104+
fold1_wrap,
101105
fold1_100,
102106
}
103107

@@ -115,7 +119,7 @@ def_benchs!{
115119

116120
def_benchs!{
117121
8,
118-
fold1,
122+
fold1_wrap,
119123
fold1_08,
120124
}
121125

src/size_hint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn add_scalar(sh: SizeHint, x: usize) -> SizeHint {
2929
}
3030

3131
/// Subtract `x` correctly from a `SizeHint`.
32+
#[cfg(feature = "use_alloc")]
3233
#[inline]
3334
pub fn sub_scalar(sh: SizeHint, x: usize) -> SizeHint {
3435
let (mut low, mut hi) = sh;

tests/quick.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
//!
44
//! In particular we test the tedious size_hint and exact size correctness.
55
6+
#[path = "../wrappers.rs"]
7+
mod wrappers;
8+
69
use quickcheck as qc;
710
use std::default::Default;
811
use std::num::Wrapping;
@@ -24,14 +27,17 @@ use itertools::free::{
2427
put_back,
2528
put_back_n,
2629
rciter,
27-
zip,
2830
zip_eq,
2931
};
3032

33+
use wrappers::free::zip;
34+
3135
use rand::Rng;
3236
use rand::seq::SliceRandom;
3337
use quickcheck::TestResult;
3438

39+
use crate::wrappers::Ext;
40+
3541
/// Trait for size hint modifier types
3642
trait HintKind: Copy + Send + qc::Arbitrary {
3743
fn loosen_bounds(&self, org_hint: (usize, Option<usize>)) -> (usize, Option<usize>);
@@ -635,12 +641,12 @@ quickcheck! {
635641
exact_size_for_this(a.iter().interleave_shortest(&b))
636642
}
637643
fn size_intersperse(a: Iter<i16>, x: i16) -> bool {
638-
correct_size_hint(a.intersperse(x))
644+
correct_size_hint(a.intersperse_wrap(x))
639645
}
640646
fn equal_intersperse(a: Vec<i32>, x: i32) -> bool {
641647
let mut inter = false;
642648
let mut i = 0;
643-
for elt in a.iter().cloned().intersperse(x) {
649+
for elt in a.iter().cloned().intersperse_wrap(x) {
644650
if inter {
645651
if elt != x { return false }
646652
} else {
@@ -1243,8 +1249,8 @@ quickcheck! {
12431249
return TestResult::discard();
12441250
}
12451251

1246-
let min = cloned(&a).fold1(f64::min);
1247-
let max = cloned(&a).fold1(f64::max);
1252+
let min = cloned(&a).fold1_wrap(f64::min);
1253+
let max = cloned(&a).fold1_wrap(f64::max);
12481254

12491255
let minmax = cloned(&a).minmax();
12501256
let expected = match a.len() {
@@ -1405,7 +1411,7 @@ quickcheck! {
14051411
.map(|i| (i % modulo, i))
14061412
.into_group_map()
14071413
.into_iter()
1408-
.map(|(key, vals)| (key, vals.into_iter().fold1(|acc, val| acc + val).unwrap()))
1414+
.map(|(key, vals)| (key, vals.into_iter().fold1_wrap(|acc, val| acc + val).unwrap()))
14091415
.collect::<HashMap<_,_>>();
14101416
assert_eq!(lookup, group_map_lookup);
14111417

tests/specializations.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
#[path = "../wrappers.rs"]
2+
mod wrappers;
3+
14
use itertools::Itertools;
25
use std::fmt::Debug;
36
use quickcheck::quickcheck;
47

8+
use crate::wrappers::Ext;
9+
510
struct Unspecialized<I>(I);
611
impl<I> Iterator for Unspecialized<I>
712
where
@@ -74,7 +79,7 @@ fn test_specializations<IterItem, Iter>(
7479

7580
quickcheck! {
7681
fn intersperse(v: Vec<u8>) -> () {
77-
test_specializations(&v.into_iter().intersperse(0));
82+
test_specializations(&v.into_iter().intersperse_wrap(0));
7883
}
7984
}
8085

tests/test_core.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
//! except according to those terms.
66
#![no_std]
77

8+
#[path = "../wrappers.rs"]
9+
mod wrappers;
10+
811
use core::iter;
912
use itertools as it;
1013
use crate::it::Itertools;
@@ -16,6 +19,7 @@ use crate::it::free::put_back;
1619
use crate::it::iproduct;
1720
use crate::it::izip;
1821
use crate::it::chain;
22+
use crate::wrappers::Ext;
1923

2024
#[test]
2125
fn product2() {
@@ -278,7 +282,7 @@ fn part() {
278282
#[test]
279283
fn tree_fold1() {
280284
for i in 0..100 {
281-
assert_eq!((0..i).tree_fold1(|x, y| x + y), (0..i).fold1(|x, y| x + y));
285+
assert_eq!((0..i).tree_fold1(|x, y| x + y), (0..i).fold1_wrap(|x, y| x + y));
282286
}
283287
}
284288

tests/test_std.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
#[path = "../wrappers.rs"]
2+
mod wrappers;
3+
14
use quickcheck as qc;
25
use rand::{distributions::{Distribution, Standard}, Rng, SeedableRng, rngs::StdRng};
36
use rand::{seq::SliceRandom, thread_rng};
47
use std::{cmp::min, fmt::Debug, marker::PhantomData};
58
use itertools as it;
6-
use crate::it::Itertools;
9+
use crate::{it::Itertools, wrappers::Ext};
710
use crate::it::ExactlyOneError;
811
use crate::it::multizip;
912
use crate::it::multipeek;
@@ -121,12 +124,12 @@ fn unique() {
121124
#[test]
122125
fn intersperse() {
123126
let xs = ["a", "", "b", "c"];
124-
let v: Vec<&str> = xs.iter().cloned().intersperse(", ").collect();
127+
let v: Vec<&str> = xs.iter().cloned().intersperse_wrap(", ").collect();
125128
let text: String = v.concat();
126129
assert_eq!(text, "a, , b, c".to_string());
127130

128131
let ys = [0, 1, 2, 3];
129-
let mut it = ys[..0].iter().copied().intersperse(1);
132+
let mut it = ys[..0].iter().copied().intersperse_wrap(1);
130133
assert!(it.next() == None);
131134
}
132135

wrappers.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! This module helps suppress two kinds of warnings: `deprecated` and `unstable_name_collisions`.
2+
//! New items are created that are noop-wrappers of the original items.
3+
//! The items' original paths are preserved.
4+
5+
use itertools::Itertools;
6+
7+
pub mod free {
8+
// it seems the compiler is not able to discern that this is used
9+
#[allow(dead_code)]
10+
pub fn zip<I, J>(i: I, j: J) -> core::iter::Zip<I::IntoIter, J::IntoIter>
11+
where I: IntoIterator,
12+
J: IntoIterator
13+
{
14+
#[allow(deprecated)]
15+
itertools::free::zip(i, j)
16+
}
17+
}
18+
19+
pub trait Ext: Itertools {
20+
fn intersperse_wrap(self, element: Self::Item) -> itertools::Intersperse<Self>
21+
where
22+
Self: Sized,
23+
Self::Item: Clone,
24+
{
25+
<Self as Itertools>::intersperse(self, element)
26+
}
27+
28+
fn fold1_wrap<F>(self, f: F) -> Option<Self::Item>
29+
where F: FnMut(Self::Item, Self::Item) -> Self::Item,
30+
Self: Sized,
31+
{
32+
#[allow(deprecated)]
33+
<Self as Itertools>::fold1(self, f)
34+
}
35+
}
36+
37+
impl<T: Itertools> Ext for T {}
38+

0 commit comments

Comments
 (0)