Skip to content

Commit 129259e

Browse files
mightyiamwarren2k
andcommitted
build: resolve warnings
Co-authored-by: warren2k <[email protected]>
1 parent e41823f commit 129259e

File tree

8 files changed

+88
-18
lines changed

8 files changed

+88
-18
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
@@ -44,15 +48,15 @@ mod specialization {
4448
let arr = [1; 1024];
4549

4650
c.bench_function("internal specialized", move |b| {
47-
b.iter(|| arr.iter().intersperse(&0).fold(0, |acc, x| acc + x))
51+
b.iter(|| arr.iter().intersperse_wrap(&0).fold(0, |acc, x| acc + x))
4852
});
4953
}
5054

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

5458
c.bench_function("internal unspecialized", move |b| {
55-
b.iter(|| Unspecialized(arr.iter().intersperse(&0)).fold(0, |acc, x| acc + x))
59+
b.iter(|| Unspecialized(arr.iter().intersperse_wrap(&0)).fold(0, |acc, x| acc + x))
5660
});
5761
}
5862
}

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

48
trait IterEx: Iterator {
59
// Another efficient implementation against which to compare,
@@ -19,7 +23,7 @@ trait IterEx: Iterator {
1923
}
2024
stack.push(x);
2125
});
22-
stack.into_iter().fold1(f)
26+
stack.into_iter().fold1_wrap(f)
2327
}
2428
}
2529
impl<T: Iterator> IterEx for T {}
@@ -83,7 +87,7 @@ macro_rules! def_benchs {
8387

8488
def_benchs! {
8589
10_000,
86-
fold1,
90+
fold1_wrap,
8791
fold1_10k,
8892
}
8993

@@ -101,7 +105,7 @@ def_benchs! {
101105

102106
def_benchs! {
103107
100,
104-
fold1,
108+
fold1_wrap,
105109
fold1_100,
106110
}
107111

@@ -119,7 +123,7 @@ def_benchs! {
119123

120124
def_benchs! {
121125
8,
122-
fold1,
126+
fold1_wrap,
123127
fold1_08,
124128
}
125129

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,8 +3,11 @@
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 itertools::free::{
7-
cloned, enumerate, multipeek, peek_nth, put_back, put_back_n, rciter, zip, zip_eq,
10+
cloned, enumerate, multipeek, peek_nth, put_back, put_back_n, rciter, zip_eq,
811
};
912
use itertools::Itertools;
1013
use itertools::{iproduct, izip, multizip, EitherOrBoth};
@@ -14,11 +17,14 @@ use std::collections::{HashMap, HashSet};
1417
use std::default::Default;
1518
use std::num::Wrapping;
1619
use std::ops::Range;
20+
use wrappers::free::zip;
1721

1822
use quickcheck::TestResult;
1923
use rand::seq::SliceRandom;
2024
use rand::Rng;
2125

26+
use crate::wrappers::Ext;
27+
2228
/// Trait for size hint modifier types
2329
trait HintKind: Copy + Send + qc::Arbitrary {
2430
fn loosen_bounds(&self, org_hint: (usize, Option<usize>)) -> (usize, Option<usize>);
@@ -641,12 +647,12 @@ quickcheck! {
641647
exact_size_for_this(a.iter().interleave_shortest(&b))
642648
}
643649
fn size_intersperse(a: Iter<i16>, x: i16) -> bool {
644-
correct_size_hint(a.intersperse(x))
650+
correct_size_hint(a.intersperse_wrap(x))
645651
}
646652
fn equal_intersperse(a: Vec<i32>, x: i32) -> bool {
647653
let mut inter = false;
648654
let mut i = 0;
649-
for elt in a.iter().cloned().intersperse(x) {
655+
for elt in a.iter().cloned().intersperse_wrap(x) {
650656
if inter {
651657
if elt != x { return false }
652658
} else {
@@ -1249,8 +1255,8 @@ quickcheck! {
12491255
return TestResult::discard();
12501256
}
12511257

1252-
let min = cloned(&a).fold1(f64::min);
1253-
let max = cloned(&a).fold1(f64::max);
1258+
let min = cloned(&a).fold1_wrap(f64::min);
1259+
let max = cloned(&a).fold1_wrap(f64::max);
12541260

12551261
let minmax = cloned(&a).minmax();
12561262
let expected = match a.len() {
@@ -1411,7 +1417,7 @@ quickcheck! {
14111417
.map(|i| (i % modulo, i))
14121418
.into_group_map()
14131419
.into_iter()
1414-
.map(|(key, vals)| (key, vals.into_iter().fold1(|acc, val| acc + val).unwrap()))
1420+
.map(|(key, vals)| (key, vals.into_iter().fold1_wrap(|acc, val| acc + val).unwrap()))
14151421
.collect::<HashMap<_,_>>();
14161422
assert_eq!(lookup, group_map_lookup);
14171423

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 quickcheck::quickcheck;
36
use std::fmt::Debug;
47

8+
use crate::wrappers::Ext;
9+
510
struct Unspecialized<I>(I);
611
impl<I> Iterator for Unspecialized<I>
712
where
@@ -73,7 +78,7 @@ where
7378

7479
quickcheck! {
7580
fn intersperse(v: Vec<u8>) -> () {
76-
test_specializations(&v.into_iter().intersperse(0));
81+
test_specializations(&v.into_iter().intersperse_wrap(0));
7782
}
7883
}
7984

tests/test_core.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! option. This file may not be copied, modified, or distributed
55
//! except according to those terms.
66
#![no_std]
7+
#[path = "../wrappers.rs"]
8+
mod wrappers;
79

810
use crate::it::chain;
911
use crate::it::free::put_back;
@@ -17,6 +19,8 @@ use crate::it::Itertools;
1719
use core::iter;
1820
use itertools as it;
1921

22+
use crate::wrappers::Ext;
23+
2024
#[test]
2125
fn product2() {
2226
let s = "αβ";
@@ -280,7 +284,10 @@ fn part() {
280284
#[test]
281285
fn tree_fold1() {
282286
for i in 0..100 {
283-
assert_eq!((0..i).tree_fold1(|x, y| x + y), (0..i).fold1(|x, y| x + y));
287+
assert_eq!(
288+
(0..i).tree_fold1(|x, y| x + y),
289+
(0..i).fold1_wrap(|x, y| x + y)
290+
);
284291
}
285292
}
286293

tests/test_std.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[path = "../wrappers.rs"]
2+
mod wrappers;
3+
14
use crate::it::cloned;
25
use crate::it::free::put_back_n;
36
use crate::it::free::rciter;
@@ -9,6 +12,8 @@ use crate::it::peek_nth;
912
use crate::it::ExactlyOneError;
1013
use crate::it::FoldWhile;
1114
use crate::it::Itertools;
15+
use crate::wrappers::Ext;
16+
1217
use itertools as it;
1318
use quickcheck as qc;
1419
use rand::{
@@ -138,12 +143,12 @@ fn unique() {
138143
#[test]
139144
fn intersperse() {
140145
let xs = ["a", "", "b", "c"];
141-
let v: Vec<&str> = xs.iter().cloned().intersperse(", ").collect();
146+
let v: Vec<&str> = xs.iter().cloned().intersperse_wrap(", ").collect();
142147
let text: String = v.concat();
143148
assert_eq!(text, "a, , b, c".to_string());
144149

145150
let ys = [0, 1, 2, 3];
146-
let mut it = ys[..0].iter().copied().intersperse(1);
151+
let mut it = ys[..0].iter().copied().intersperse_wrap(1);
147152
assert!(it.next() == None);
148153
}
149154

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)