blob: 98c98b9b627b56bc68cf470d99c6376267e79fa5 (
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
|
// Test that macros can be defined in the labeled block. This should not trigger an error about
// statements not being allowed in that position, and should of course work as expected.
//@ run-pass
#![allow(incomplete_features)]
#![feature(loop_match)]
enum State {
A,
B,
C,
}
fn main() {
let mut state = State::A;
#[loop_match]
'a: loop {
state = 'blk: {
macro_rules! const_continue {
($e:expr) => {
#[const_continue]
break 'blk $e;
};
}
match state {
State::A => {
const_continue!(State::B);
}
State::B => {
// Without special logic, the compiler believes this is a
// reassignment to an immutable variable because of the
// `loop`. So this tests that local variables work.
let _a = 0;
if true {
const_continue!(State::C);
} else {
const_continue!(State::A);
}
}
State::C => break 'a,
}
};
}
assert!(matches!(state, State::C))
}
|