summaryrefslogtreecommitdiffstats
path: root/tests/ui/issues/issue-29746.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/issues/issue-29746.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/issues/issue-29746.rs')
-rw-r--r--tests/ui/issues/issue-29746.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui/issues/issue-29746.rs b/tests/ui/issues/issue-29746.rs
new file mode 100644
index 000000000..3470a7e09
--- /dev/null
+++ b/tests/ui/issues/issue-29746.rs
@@ -0,0 +1,36 @@
+// run-pass
+// zip!(a1,a2,a3,a4) is equivalent to:
+// a1.zip(a2).zip(a3).zip(a4).map(|(((x1,x2),x3),x4)| (x1,x2,x3,x4))
+macro_rules! zip {
+ // Entry point
+ ([$a:expr, $b:expr, $($rest:expr),*]) => {
+ zip!([$($rest),*], $a.zip($b), (x,y), [x,y])
+ };
+
+ // Intermediate steps to build the zipped expression, the match pattern
+ // and the output tuple of the closure, using macro hygiene to repeatedly
+ // introduce new variables named 'x'.
+ ([$a:expr, $($rest:expr),*], $zip:expr, $pat:pat, [$($flat:expr),*]) => {
+ zip!([$($rest),*], $zip.zip($a), ($pat,x), [$($flat),*, x])
+ };
+
+ // Final step
+ ([], $zip:expr, $pat:pat, [$($flat:expr),+]) => {
+ $zip.map(|$pat| ($($flat),+))
+ };
+
+ // Comma
+ ([$a:expr], $zip:expr, $pat:pat, [$($flat:expr),*]) => {
+ zip!([$a,], $zip, $pat, [$($flat),*])
+ };
+}
+
+fn main() {
+ let p1 = vec![1i32, 2].into_iter();
+ let p2 = vec!["10", "20"].into_iter();
+ let p3 = vec![100u16, 200].into_iter();
+ let p4 = vec![1000i64, 2000].into_iter();
+
+ let e = zip!([p1,p2,p3,p4]).collect::<Vec<_>>();
+ assert_eq!(e[0], (1i32,"10",100u16,1000i64));
+}