about summary refs log tree commit diff
path: root/tests/ui/loop-match/nested.rs
blob: aaddfae11defa1e60ab0f93d17ba9833b0aa1a9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
}