forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel-on-block-suggest-move.rs
90 lines (84 loc) · 3.69 KB
/
label-on-block-suggest-move.rs
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
84
85
86
87
88
89
90
// see https://github.com/rust-lang/rust/issues/138585
#![allow(break_with_label_and_loop)] // doesn't work locally
fn main() {
loop 'a: {}
//~^ ERROR: block label not supported here
//~| HELP: if you meant to label the loop, move this label before the loop
while false 'a: {}
//~^ ERROR: block label not supported here
//~| HELP: if you meant to label the loop, move this label before the loop
for i in [0] 'a: {}
//~^ ERROR: block label not supported here
//~| HELP: if you meant to label the loop, move this label before the loop
'a: loop {
// first block is parsed as the break expr's value with or without parens
while break 'a 'b: {} 'c: {}
//~^ ERROR: block label not supported here
//~| HELP: if you meant to label the loop, move this label before the loop
while break 'a ('b: {}) 'c: {}
//~^ ERROR: block label not supported here
//~| HELP: if you meant to label the loop, move this label before the loop
// without the parens, the first block is parsed as the while-loop's body
// (see the 'no errors' section)
// #[allow(break_with_label_and_loop)] (doesn't work locally)
while (break 'a {}) 'c: {}
//~^ ERROR: block label not supported here
//~| HELP: if you meant to label the loop, move this label before the loop
}
// do not suggest moving the label if there is already a label on the loop
'a: loop 'b: {}
//~^ ERROR: block label not supported here
//~| HELP: remove this block label
'a: while false 'b: {}
//~^ ERROR: block label not supported here
//~| HELP: remove this block label
'a: for i in [0] 'b: {}
//~^ ERROR: block label not supported here
//~| HELP: remove this block label
'a: loop {
// first block is parsed as the break expr's value with or without parens
'd: while break 'a 'b: {} 'c: {}
//~^ ERROR: block label not supported here
//~| HELP: remove this block label
'd: while break 'a ('b: {}) 'c: {}
//~^ ERROR: block label not supported here
//~| HELP: remove this block label
// without the parens, the first block is parsed as the while-loop's body
// (see the 'no errors' section)
// #[allow(break_with_label_and_loop)] (doesn't work locally)
'd: while (break 'a {}) 'c: {}
//~^ ERROR: block label not supported here
//~| HELP: remove this block label
}
// no errors
loop { 'a: {} }
'a: loop { 'b: {} }
while false { 'a: {} }
'a: while false { 'b: {} }
for i in [0] { 'a: {} }
'a: for i in [0] { 'b: {} }
'a: {}
'a: { 'b: {} }
'a: loop {
// first block is parsed as the break expr's value if it is a labeled block
while break 'a 'b: {} {}
'd: while break 'a 'b: {} {}
while break 'a ('b: {}) {}
'd: while break 'a ('b: {}) {}
// first block is parsed as the while-loop's body if it has no label
// (the break expr is parsed as having no value),
// so the second block is a normal stmt-block, and the label is allowed
while break 'a {} 'c: {}
while break 'a {} {}
'd: while break 'a {} 'c: {}
'd: while break 'a {} {}
}
// unrelated errors that should not be affected
'a: 'b: {}
//~^ ERROR: expected `while`, `for`, `loop` or `{` after a label
//~| HELP: consider removing the label
loop { while break 'b: {} {} }
//~^ ERROR: parentheses are required around this expression to avoid confusion with a labeled break expression
//~| HELP: wrap the expression in parentheses
//~| ERROR: `break` or `continue` with no label in the condition of a `while` loop [E0590]
}