Skip to content

Commit 3067893

Browse files
Fix/ignore warnings within doctests
1 parent e41a62b commit 3067893

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

src/free.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub use crate::zip_eq_impl::zip_eq;
3636
/// ```
3737
/// use itertools::intersperse;
3838
///
39-
/// itertools::assert_equal(intersperse((0..3), 8), vec![0, 8, 1, 8, 2]);
39+
/// itertools::assert_equal(intersperse(0..3, 8), vec![0, 8, 1, 8, 2]);
4040
/// ```
4141
pub fn intersperse<I>(iterable: I, element: I::Item) -> Intersperse<I::IntoIter>
4242
where
@@ -55,7 +55,7 @@ where
5555
/// use itertools::intersperse_with;
5656
///
5757
/// let mut i = 10;
58-
/// itertools::assert_equal(intersperse_with((0..3), || { i -= 1; i }), vec![0, 9, 1, 8, 2]);
58+
/// itertools::assert_equal(intersperse_with(0..3, || { i -= 1; i }), vec![0, 9, 1, 8, 2]);
5959
/// assert_eq!(i, 8);
6060
/// ```
6161
pub fn intersperse_with<I, F>(iterable: I, element: F) -> IntersperseWith<I::IntoIter, F>
@@ -75,6 +75,7 @@ where
7575
///
7676
/// for (i, elt) in enumerate(&[1, 2, 3]) {
7777
/// /* loop body */
78+
/// # let _ = (i, elt);
7879
/// }
7980
/// ```
8081
pub fn enumerate<I>(iterable: I) -> iter::Enumerate<I::IntoIter>
@@ -93,6 +94,7 @@ where
9394
///
9495
/// for elt in rev(&[1, 2, 3]) {
9596
/// /* loop body */
97+
/// # let _ = elt;
9698
/// }
9799
/// ```
98100
pub fn rev<I>(iterable: I) -> iter::Rev<I::IntoIter>

src/kmerge_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ impl<T, F: FnMut(&T, &T) -> bool> KMergePredicate<T> for F {
134134
///
135135
/// for elt in kmerge(vec![vec![0, 2, 4], vec![1, 3, 5], vec![6, 7]]) {
136136
/// /* loop body */
137+
/// # let _ = elt;
137138
/// }
138139
/// ```
139140
pub fn kmerge<I>(iterable: I) -> KMerge<<I::Item as IntoIterator>::IntoIter>

src/lib.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#![warn(missing_docs, clippy::default_numeric_fallback)]
22
#![crate_name = "itertools"]
33
#![cfg_attr(not(feature = "use_std"), no_std)]
4+
#![doc(test(attr(deny(warnings), allow(deprecated, unstable_name_collisions))))]
45

56
//! Extra iterator adaptors, functions and macros.
67
//!
78
//! To extend [`Iterator`] with methods in this crate, import
89
//! the [`Itertools`] trait:
910
//!
1011
//! ```
12+
//! # #[allow(unused_imports)]
1113
//! use itertools::Itertools;
1214
//! ```
1315
//!
@@ -29,6 +31,7 @@
2931
//!
3032
//! for elt in interleave(&[1, 2, 3], &[2, 3, 4]) {
3133
//! /* loop body */
34+
//! # let _ = elt;
3235
//! }
3336
//! ```
3437
//!
@@ -248,6 +251,7 @@ mod ziptuple;
248251
/// // from (0, 0, 0), (0, 0, 1), .., (0, 1, 0), (0, 1, 1), .. etc until (3, 3, 3)
249252
/// for (i, j, k) in iproduct!(0..4, 0..4, 0..4) {
250253
/// // ..
254+
/// # let _ = (i, j, k);
251255
/// }
252256
/// # }
253257
/// ```
@@ -375,16 +379,16 @@ macro_rules! izip {
375379
///
376380
/// Invocations of `chain!` with one argument expand to [`arg.into_iter()`](IntoIterator):
377381
/// ```
378-
/// use std::{ops::Range, slice};
382+
/// use std::ops::Range;
379383
/// use itertools::chain;
380-
/// let _: <Range<_> as IntoIterator>::IntoIter = chain!((2..6),); // trailing comma optional!
384+
/// let _: <Range<_> as IntoIterator>::IntoIter = chain!(2..6,); // trailing comma optional!
381385
/// let _: <&[_] as IntoIterator>::IntoIter = chain!(&[2, 3, 4]);
382386
/// ```
383387
///
384388
/// Invocations of `chain!` with multiple arguments [`.into_iter()`](IntoIterator) each
385389
/// argument, and then [`chain`] them together:
386390
/// ```
387-
/// use std::{iter::*, ops::Range, slice};
391+
/// use std::{iter::*, slice};
388392
/// use itertools::{assert_equal, chain};
389393
///
390394
/// // e.g., this:
@@ -1902,7 +1906,7 @@ pub trait Itertools: Iterator {
19021906
/// use itertools::Itertools;
19031907
///
19041908
/// let input = vec![vec![1], vec![3, 2, 1]];
1905-
/// let it = input.into_iter().update(|mut v| v.push(0));
1909+
/// let it = input.into_iter().update(|v| v.push(0));
19061910
/// itertools::assert_equal(it, vec![vec![1, 0], vec![3, 2, 1, 0]]);
19071911
/// ```
19081912
fn update<F>(self, updater: F) -> Update<Self, F>
@@ -2162,7 +2166,7 @@ pub trait Itertools: Iterator {
21622166
/// ```
21632167
/// use itertools::Itertools;
21642168
///
2165-
/// let mut iter = "αβγ".chars().dropping(2);
2169+
/// let iter = "αβγ".chars().dropping(2);
21662170
/// itertools::assert_equal(iter, "γ".chars());
21672171
/// ```
21682172
///
@@ -2246,14 +2250,17 @@ pub trait Itertools: Iterator {
22462250
///
22472251
/// fn process_dir_entries(entries: &[fs::DirEntry]) {
22482252
/// // ...
2253+
/// # let _ = entries;
22492254
/// }
22502255
///
2251-
/// fn do_stuff() -> std::io::Result<()> {
2256+
/// fn do_stuff() -> io::Result<()> {
22522257
/// let entries: Vec<_> = fs::read_dir(".")?.try_collect()?;
22532258
/// process_dir_entries(&entries);
22542259
///
22552260
/// Ok(())
22562261
/// }
2262+
///
2263+
/// # let _ = do_stuff;
22572264
/// ```
22582265
fn try_collect<T, U, E>(self) -> Result<U, E>
22592266
where
@@ -2404,6 +2411,7 @@ pub trait Itertools: Iterator {
24042411
/// accum = f(accum, 1);
24052412
/// accum = f(accum, 2);
24062413
/// accum = f(accum, 3);
2414+
/// # let _ = accum;
24072415
/// ```
24082416
///
24092417
/// With a `start` value of 0 and an addition as folding function,
@@ -2554,16 +2562,16 @@ pub trait Itertools: Iterator {
25542562
/// assert_eq!((1..8).map(|x| x.to_string()).tree_reduce(f),
25552563
/// Some(String::from("f(f(f(1, 2), f(3, 4)), f(f(5, 6), 7))")));
25562564
///
2557-
/// // Like fold1, an empty iterator produces None
2565+
/// // Like reduce, an empty iterator produces None
25582566
/// assert_eq!((0..0).tree_reduce(|x, y| x * y), None);
25592567
///
2560-
/// // tree_reduce matches fold1 for associative operations...
2568+
/// // tree_reduce matches reduce for associative operations...
25612569
/// assert_eq!((0..10).tree_reduce(|x, y| x + y),
2562-
/// (0..10).fold1(|x, y| x + y));
2570+
/// (0..10).reduce(|x, y| x + y));
25632571
///
25642572
/// // ...but not for non-associative ones
25652573
/// assert_ne!((0..10).tree_reduce(|x, y| x - y),
2566-
/// (0..10).fold1(|x, y| x - y));
2574+
/// (0..10).reduce(|x, y| x - y));
25672575
///
25682576
/// let mut total_len_reduce = 0;
25692577
/// let reduce_res = (1..100).map(|x| x.to_string())
@@ -4350,7 +4358,7 @@ pub trait Itertools: Iterator {
43504358
/// # Examples
43514359
/// ```
43524360
/// # use itertools::Itertools;
4353-
/// let counts = [1, 1, 1, 3, 3, 5].into_iter().counts();
4361+
/// let counts = [1, 1, 1, 3, 3, 5].iter().counts();
43544362
/// assert_eq!(counts[&1], 3);
43554363
/// assert_eq!(counts[&3], 2);
43564364
/// assert_eq!(counts[&5], 1);
@@ -4376,6 +4384,7 @@ pub trait Itertools: Iterator {
43764384
/// # use itertools::Itertools;
43774385
/// struct Character {
43784386
/// first_name: &'static str,
4387+
/// # #[allow(dead_code)]
43794388
/// last_name: &'static str,
43804389
/// }
43814390
///

src/merge_join.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub type Merge<I, J> = MergeBy<I, J, MergeLte>;
3131
///
3232
/// for elt in merge(&[1, 2, 3], &[2, 3, 4]) {
3333
/// /* loop body */
34+
/// # let _ = elt;
3435
/// }
3536
/// ```
3637
pub fn merge<I, J>(

src/zip_eq_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct ZipEq<I, J> {
2121
/// let data = [1, 2, 3, 4, 5];
2222
/// for (a, b) in zip_eq(&data[..data.len() - 1], &data[1..]) {
2323
/// /* loop body */
24+
/// # let _ = (a, b);
2425
/// }
2526
/// ```
2627
pub fn zip_eq<I, J>(i: I, j: J) -> ZipEq<I::IntoIter, J::IntoIter>

0 commit comments

Comments
 (0)