From eabc235f22f0701c26b0fa341609122f1781cf2e Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 14 Oct 2023 20:11:46 +0200 Subject: [PATCH 1/3] check_specialized only needed within function --- tests/specializations.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/specializations.rs b/tests/specializations.rs index 4fa6c33df..47c797291 100644 --- a/tests/specializations.rs +++ b/tests/specializations.rs @@ -17,23 +17,20 @@ where } } -macro_rules! check_specialized { - ($src:expr, |$it:pat| $closure:expr) => { - let $it = $src.clone(); - let v1 = $closure; - - let $it = Unspecialized($src.clone()); - let v2 = $closure; - - assert_eq!(v1, v2); - }; -} - fn test_specializations(it: &Iter) where IterItem: Eq + Debug + Clone, Iter: Iterator + Clone, { + macro_rules! check_specialized { + ($src:expr, |$it:pat| $closure:expr) => { + let $it = $src.clone(); + let v1 = $closure; + let $it = Unspecialized($src.clone()); + let v2 = $closure; + assert_eq!(v1, v2); + }; + } check_specialized!(it, |i| i.count()); check_specialized!(it, |i| i.last()); check_specialized!(it, |i| i.collect::>()); From fbe6e32fc8d5d382f64540f03c5aab5eb931401e Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 14 Oct 2023 20:20:00 +0200 Subject: [PATCH 2/3] Test specializations for next'ed iterators --- tests/specializations.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/specializations.rs b/tests/specializations.rs index 47c797291..ba170c42c 100644 --- a/tests/specializations.rs +++ b/tests/specializations.rs @@ -24,12 +24,17 @@ where { macro_rules! check_specialized { ($src:expr, |$it:pat| $closure:expr) => { - let $it = $src.clone(); - let v1 = $closure; - let $it = Unspecialized($src.clone()); - let v2 = $closure; - assert_eq!(v1, v2); - }; + // Many iterators special-case the first elements, so we test specializations for iterators that have already been advanced. + let mut src = $src.clone(); + for _ in 0..5 { + let $it = src.clone(); + let v1 = $closure; + let $it = Unspecialized(src.clone()); + let v2 = $closure; + assert_eq!(v1, v2); + src.next(); + } + } } check_specialized!(it, |i| i.count()); check_specialized!(it, |i| i.last()); From 5d88dedc71bf112f6a02112fae5cfd2084d2de64 Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 14 Oct 2023 20:27:43 +0200 Subject: [PATCH 3/3] Add TODO process_results is as of now tested separately because the corresponding iterator is not exposed nicely, and because it is not `Clone`. However, the respective tests already diverged. Instead of fixing process_results, we should strive to uniformly use test_specializations for ProcessResults, too. --- tests/specializations.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/specializations.rs b/tests/specializations.rs index ba170c42c..3f5e10685 100644 --- a/tests/specializations.rs +++ b/tests/specializations.rs @@ -129,6 +129,7 @@ quickcheck! { } quickcheck! { + // TODO Replace this function by a normal call to test_specializations fn process_results(v: Vec>) -> () { helper(v.iter().copied()); helper(v.iter().copied().filter(Result::is_ok));