diff --git a/tests/specializations.rs b/tests/specializations.rs index 4fa6c33df..3f5e10685 100644 --- a/tests/specializations.rs +++ b/tests/specializations.rs @@ -17,23 +17,25 @@ 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) => { + // 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()); check_specialized!(it, |i| i.collect::>()); @@ -127,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));