Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions tests/specializations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IterItem, Iter>(it: &Iter)
where
IterItem: Eq + Debug + Clone,
Iter: Iterator<Item = IterItem> + 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::<Vec<_>>());
Expand Down Expand Up @@ -127,6 +129,7 @@ quickcheck! {
}

quickcheck! {
// TODO Replace this function by a normal call to test_specializations
fn process_results(v: Vec<Result<u8, u8>>) -> () {
helper(v.iter().copied());
helper(v.iter().copied().filter(Result::is_ok));
Expand Down