about summary refs log tree commit diff
path: root/tests/ui/loop-match/or-patterns.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/loop-match/or-patterns.rs')
-rw-r--r--tests/ui/loop-match/or-patterns.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/ui/loop-match/or-patterns.rs b/tests/ui/loop-match/or-patterns.rs
new file mode 100644
index 00000000000..775243b9c62
--- /dev/null
+++ b/tests/ui/loop-match/or-patterns.rs
@@ -0,0 +1,54 @@
+// Test that `#[loop_match]` supports or-patterns.
+
+//@ run-pass
+
+#![allow(incomplete_features)]
+#![feature(loop_match)]
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+enum State {
+    A,
+    B,
+    C,
+    D,
+}
+
+fn main() {
+    let mut states = vec![];
+    let mut first = true;
+    let mut state = State::A;
+    #[loop_match]
+    'a: loop {
+        state = 'blk: {
+            match state {
+                State::A => {
+                    states.push(state);
+                    if first {
+                        #[const_continue]
+                        break 'blk State::B;
+                    } else {
+                        #[const_continue]
+                        break 'blk State::D;
+                    }
+                }
+                State::B | State::D => {
+                    states.push(state);
+                    if first {
+                        first = false;
+                        #[const_continue]
+                        break 'blk State::A;
+                    } else {
+                        #[const_continue]
+                        break 'blk State::C;
+                    }
+                }
+                State::C => {
+                    states.push(state);
+                    break 'a;
+                }
+            }
+        }
+    }
+
+    assert_eq!(states, [State::A, State::B, State::A, State::D, State::C]);
+}