]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-29746.rs
Merge commit '6ed6f1e6a1a8f414ba7e6d9b8222e7e5a1686e42' into clippyup
[rust.git] / src / test / ui / issues / issue-29746.rs
1 // run-pass
2 // zip!(a1,a2,a3,a4) is equivalent to:
3 //  a1.zip(a2).zip(a3).zip(a4).map(|(((x1,x2),x3),x4)| (x1,x2,x3,x4))
4 macro_rules! zip {
5     // Entry point
6     ([$a:expr, $b:expr, $($rest:expr),*]) => {
7         zip!([$($rest),*], $a.zip($b), (x,y), [x,y])
8     };
9
10     // Intermediate steps to build the zipped expression, the match pattern, and
11     //  and the output tuple of the closure, using macro hygiene to repeatedly
12     //  introduce new variables named 'x'.
13     ([$a:expr, $($rest:expr),*], $zip:expr, $pat:pat, [$($flat:expr),*]) => {
14         zip!([$($rest),*], $zip.zip($a), ($pat,x), [$($flat),*, x])
15     };
16
17     // Final step
18     ([], $zip:expr, $pat:pat, [$($flat:expr),+]) => {
19         $zip.map(|$pat| ($($flat),+))
20     };
21
22     // Comma
23     ([$a:expr], $zip:expr, $pat:pat, [$($flat:expr),*]) => {
24         zip!([$a,], $zip, $pat, [$($flat),*])
25     };
26 }
27
28 fn main() {
29     let p1 = vec![1i32,    2].into_iter();
30     let p2 = vec!["10",    "20"].into_iter();
31     let p3 = vec![100u16,  200].into_iter();
32     let p4 = vec![1000i64, 2000].into_iter();
33
34     let e = zip!([p1,p2,p3,p4]).collect::<Vec<_>>();
35     assert_eq!(e[0], (1i32,"10",100u16,1000i64));
36 }