about summary refs log tree commit diff
path: root/tests/ui/loop-match/nested.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/loop-match/nested.rs')
-rw-r--r--tests/ui/loop-match/nested.rs83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/ui/loop-match/nested.rs b/tests/ui/loop-match/nested.rs
new file mode 100644
index 00000000000..aaddfae11de
--- /dev/null
+++ b/tests/ui/loop-match/nested.rs
@@ -0,0 +1,83 @@
+// Test that a nested `#[loop_match]` works as expected, and that e.g. a
+// `#[const_continue]` of the inner `#[loop_match]` does not interact with the
+// outer `#[loop_match]`.
+
+//@ run-pass
+
+#![allow(incomplete_features)]
+#![feature(loop_match)]
+
+enum State1 {
+    A,
+    B,
+    C,
+}
+
+enum State2 {
+    X,
+    Y,
+    Z,
+}
+
+fn main() {
+    assert_eq!(run(), concat!("ab", "xyz", "xyz", "c"))
+}
+
+fn run() -> String {
+    let mut accum = String::new();
+
+    let mut state1 = State1::A;
+    let mut state2 = State2::X;
+
+    let mut first = true;
+
+    #[loop_match]
+    'a: loop {
+        state1 = 'blk1: {
+            match state1 {
+                State1::A => {
+                    accum.push('a');
+                    #[const_continue]
+                    break 'blk1 State1::B;
+                }
+                State1::B => {
+                    accum.push('b');
+                    #[loop_match]
+                    loop {
+                        state2 = 'blk2: {
+                            match state2 {
+                                State2::X => {
+                                    accum.push('x');
+                                    #[const_continue]
+                                    break 'blk2 State2::Y;
+                                }
+                                State2::Y => {
+                                    accum.push('y');
+                                    #[const_continue]
+                                    break 'blk2 State2::Z;
+                                }
+                                State2::Z => {
+                                    accum.push('z');
+                                    if first {
+                                        first = false;
+                                        #[const_continue]
+                                        break 'blk2 State2::X;
+                                    } else {
+                                        #[const_continue]
+                                        break 'blk1 State1::C;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+                State1::C => {
+                    accum.push('c');
+                    break 'a;
+                }
+            }
+        }
+    }
+
+    accum
+}