Skip to content

Commit c065234

Browse files
committed
Add more misspelled label tests
1 parent 8a13abb commit c065234

File tree

4 files changed

+173
-15
lines changed

4 files changed

+173
-15
lines changed

src/test/ui/label/label_misspelled.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,46 @@
1+
#![warn(unused_labels)]
2+
13
fn main() {
24
'while_loop: while true { //~ WARN denote infinite loops with
5+
//~^ WARN unused label
36
while_loop;
47
//~^ ERROR cannot find value `while_loop` in this scope
58
};
69
'while_let: while let Some(_) = Some(()) {
10+
//~^ WARN unused label
711
while_let;
812
//~^ ERROR cannot find value `while_let` in this scope
913
}
1014
'for_loop: for _ in 0..3 {
15+
//~^ WARN unused label
1116
for_loop;
1217
//~^ ERROR cannot find value `for_loop` in this scope
1318
};
1419
'LOOP: loop {
20+
//~^ WARN unused label
1521
LOOP;
1622
//~^ ERROR cannot find value `LOOP` in this scope
1723
};
1824
}
1925

2026
fn foo() {
2127
'LOOP: loop {
28+
//~^ WARN unused label
2229
break LOOP;
2330
//~^ ERROR cannot find value `LOOP` in this scope
2431
};
2532
'while_loop: while true { //~ WARN denote infinite loops with
33+
//~^ WARN unused label
2634
break while_loop;
2735
//~^ ERROR cannot find value `while_loop` in this scope
2836
};
2937
'while_let: while let Some(_) = Some(()) {
38+
//~^ WARN unused label
3039
break while_let;
3140
//~^ ERROR cannot find value `while_let` in this scope
3241
}
3342
'for_loop: for _ in 0..3 {
43+
//~^ WARN unused label
3444
break for_loop;
3545
//~^ ERROR cannot find value `for_loop` in this scope
3646
};
@@ -39,14 +49,17 @@ fn foo() {
3949
fn bar() {
4050
let foo = ();
4151
'while_loop: while true { //~ WARN denote infinite loops with
52+
//~^ WARN unused label
4253
break foo;
4354
//~^ ERROR `break` with value from a `while` loop
4455
};
4556
'while_let: while let Some(_) = Some(()) {
57+
//~^ WARN unused label
4658
break foo;
4759
//~^ ERROR `break` with value from a `while` loop
4860
}
4961
'for_loop: for _ in 0..3 {
62+
//~^ WARN unused label
5063
break foo;
5164
//~^ ERROR `break` with value from a `for` loop
5265
};

src/test/ui/label/label_misspelled.stderr

+98-15
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,185 @@
11
error[E0425]: cannot find value `while_loop` in this scope
2-
--> $DIR/label_misspelled.rs:3:9
2+
--> $DIR/label_misspelled.rs:6:9
33
|
44
LL | 'while_loop: while true {
55
| ----------- a label with a similar name exists
6+
LL |
67
LL | while_loop;
78
| ^^^^^^^^^^ not found in this scope
89

910
error[E0425]: cannot find value `while_let` in this scope
10-
--> $DIR/label_misspelled.rs:7:9
11+
--> $DIR/label_misspelled.rs:11:9
1112
|
1213
LL | 'while_let: while let Some(_) = Some(()) {
1314
| ---------- a label with a similar name exists
15+
LL |
1416
LL | while_let;
1517
| ^^^^^^^^^ not found in this scope
1618

1719
error[E0425]: cannot find value `for_loop` in this scope
18-
--> $DIR/label_misspelled.rs:11:9
20+
--> $DIR/label_misspelled.rs:16:9
1921
|
2022
LL | 'for_loop: for _ in 0..3 {
2123
| --------- a label with a similar name exists
24+
LL |
2225
LL | for_loop;
2326
| ^^^^^^^^ not found in this scope
2427

2528
error[E0425]: cannot find value `LOOP` in this scope
26-
--> $DIR/label_misspelled.rs:15:9
29+
--> $DIR/label_misspelled.rs:21:9
2730
|
2831
LL | 'LOOP: loop {
2932
| ----- a label with a similar name exists
33+
LL |
3034
LL | LOOP;
3135
| ^^^^ not found in this scope
3236

3337
error[E0425]: cannot find value `LOOP` in this scope
34-
--> $DIR/label_misspelled.rs:22:15
38+
--> $DIR/label_misspelled.rs:29:15
3539
|
3640
LL | 'LOOP: loop {
3741
| ----- a label with a similar name exists
42+
LL |
3843
LL | break LOOP;
3944
| ^^^^
4045
| |
4146
| not found in this scope
4247
| help: use the similarly named label: `'LOOP`
4348

4449
error[E0425]: cannot find value `while_loop` in this scope
45-
--> $DIR/label_misspelled.rs:26:15
50+
--> $DIR/label_misspelled.rs:34:15
4651
|
4752
LL | 'while_loop: while true {
4853
| ----------- a label with a similar name exists
54+
LL |
4955
LL | break while_loop;
5056
| ^^^^^^^^^^
5157
| |
5258
| not found in this scope
5359
| help: use the similarly named label: `'while_loop`
5460

5561
error[E0425]: cannot find value `while_let` in this scope
56-
--> $DIR/label_misspelled.rs:30:15
62+
--> $DIR/label_misspelled.rs:39:15
5763
|
5864
LL | 'while_let: while let Some(_) = Some(()) {
5965
| ---------- a label with a similar name exists
66+
LL |
6067
LL | break while_let;
6168
| ^^^^^^^^^
6269
| |
6370
| not found in this scope
6471
| help: use the similarly named label: `'while_let`
6572

6673
error[E0425]: cannot find value `for_loop` in this scope
67-
--> $DIR/label_misspelled.rs:34:15
74+
--> $DIR/label_misspelled.rs:44:15
6875
|
6976
LL | 'for_loop: for _ in 0..3 {
7077
| --------- a label with a similar name exists
78+
LL |
7179
LL | break for_loop;
7280
| ^^^^^^^^
7381
| |
7482
| not found in this scope
7583
| help: use the similarly named label: `'for_loop`
7684

85+
warning: unused label
86+
--> $DIR/label_misspelled.rs:4:5
87+
|
88+
LL | 'while_loop: while true {
89+
| ^^^^^^^^^^^
90+
|
91+
note: the lint level is defined here
92+
--> $DIR/label_misspelled.rs:1:9
93+
|
94+
LL | #![warn(unused_labels)]
95+
| ^^^^^^^^^^^^^
96+
7797
warning: denote infinite loops with `loop { ... }`
78-
--> $DIR/label_misspelled.rs:2:5
98+
--> $DIR/label_misspelled.rs:4:5
7999
|
80100
LL | 'while_loop: while true {
81101
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
82102
|
83103
= note: `#[warn(while_true)]` on by default
84104

105+
warning: unused label
106+
--> $DIR/label_misspelled.rs:9:5
107+
|
108+
LL | 'while_let: while let Some(_) = Some(()) {
109+
| ^^^^^^^^^^
110+
111+
warning: unused label
112+
--> $DIR/label_misspelled.rs:14:5
113+
|
114+
LL | 'for_loop: for _ in 0..3 {
115+
| ^^^^^^^^^
116+
117+
warning: unused label
118+
--> $DIR/label_misspelled.rs:19:5
119+
|
120+
LL | 'LOOP: loop {
121+
| ^^^^^
122+
123+
warning: unused label
124+
--> $DIR/label_misspelled.rs:27:5
125+
|
126+
LL | 'LOOP: loop {
127+
| ^^^^^
128+
129+
warning: unused label
130+
--> $DIR/label_misspelled.rs:32:5
131+
|
132+
LL | 'while_loop: while true {
133+
| ^^^^^^^^^^^
134+
85135
warning: denote infinite loops with `loop { ... }`
86-
--> $DIR/label_misspelled.rs:25:5
136+
--> $DIR/label_misspelled.rs:32:5
87137
|
88138
LL | 'while_loop: while true {
89139
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
90140

141+
warning: unused label
142+
--> $DIR/label_misspelled.rs:37:5
143+
|
144+
LL | 'while_let: while let Some(_) = Some(()) {
145+
| ^^^^^^^^^^
146+
147+
warning: unused label
148+
--> $DIR/label_misspelled.rs:42:5
149+
|
150+
LL | 'for_loop: for _ in 0..3 {
151+
| ^^^^^^^^^
152+
153+
warning: unused label
154+
--> $DIR/label_misspelled.rs:51:5
155+
|
156+
LL | 'while_loop: while true {
157+
| ^^^^^^^^^^^
158+
91159
warning: denote infinite loops with `loop { ... }`
92-
--> $DIR/label_misspelled.rs:41:5
160+
--> $DIR/label_misspelled.rs:51:5
93161
|
94162
LL | 'while_loop: while true {
95163
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
96164

165+
warning: unused label
166+
--> $DIR/label_misspelled.rs:56:5
167+
|
168+
LL | 'while_let: while let Some(_) = Some(()) {
169+
| ^^^^^^^^^^
170+
171+
warning: unused label
172+
--> $DIR/label_misspelled.rs:61:5
173+
|
174+
LL | 'for_loop: for _ in 0..3 {
175+
| ^^^^^^^^^
176+
97177
error[E0571]: `break` with value from a `while` loop
98-
--> $DIR/label_misspelled.rs:42:9
178+
--> $DIR/label_misspelled.rs:53:9
99179
|
100180
LL | 'while_loop: while true {
101181
| ----------------------- you can't `break` with a value in a `while` loop
182+
LL |
102183
LL | break foo;
103184
| ^^^^^^^^^ can only break with a value inside `loop` or breakable block
104185
|
@@ -112,10 +193,11 @@ LL | break 'while_loop;
112193
| ^^^^^^^^^^^
113194

114195
error[E0571]: `break` with value from a `while` loop
115-
--> $DIR/label_misspelled.rs:46:9
196+
--> $DIR/label_misspelled.rs:58:9
116197
|
117198
LL | 'while_let: while let Some(_) = Some(()) {
118199
| ---------------------------------------- you can't `break` with a value in a `while` loop
200+
LL |
119201
LL | break foo;
120202
| ^^^^^^^^^ can only break with a value inside `loop` or breakable block
121203
|
@@ -129,10 +211,11 @@ LL | break 'while_let;
129211
| ^^^^^^^^^^
130212

131213
error[E0571]: `break` with value from a `for` loop
132-
--> $DIR/label_misspelled.rs:50:9
214+
--> $DIR/label_misspelled.rs:63:9
133215
|
134216
LL | 'for_loop: for _ in 0..3 {
135217
| ------------------------ you can't `break` with a value in a `for` loop
218+
LL |
136219
LL | break foo;
137220
| ^^^^^^^^^ can only break with a value inside `loop` or breakable block
138221
|
@@ -145,7 +228,7 @@ help: alternatively, you might have meant to use the available loop label
145228
LL | break 'for_loop;
146229
| ^^^^^^^^^
147230

148-
error: aborting due to 11 previous errors; 3 warnings emitted
231+
error: aborting due to 11 previous errors; 14 warnings emitted
149232

150233
Some errors have detailed explanations: E0425, E0571.
151234
For more information about an error, try `rustc --explain E0425`.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![warn(unused_labels)]
2+
3+
fn main() {
4+
'a: for _ in 0..1 {
5+
break 'a;
6+
}
7+
'b: for _ in 0..1 {
8+
//~^ WARN unused label
9+
break b; //~ ERROR cannot find value `b` in this scope
10+
}
11+
c: for _ in 0..1 { //~ ERROR expected identifier, found keyword `for`
12+
//~^ ERROR expected `<`, found reserved identifier `_`
13+
break 'c;
14+
}
15+
d: for _ in 0..1 {
16+
break ;
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
error: expected identifier, found keyword `for`
2+
--> $DIR/label_misspelled_2.rs:11:8
3+
|
4+
LL | c: for _ in 0..1 {
5+
| ^^^ expected identifier, found keyword
6+
7+
error: expected `<`, found reserved identifier `_`
8+
--> $DIR/label_misspelled_2.rs:11:12
9+
|
10+
LL | c: for _ in 0..1 {
11+
| - ^ expected `<`
12+
| |
13+
| tried to parse a type due to this type ascription
14+
|
15+
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
16+
= note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information
17+
18+
error[E0425]: cannot find value `b` in this scope
19+
--> $DIR/label_misspelled_2.rs:9:15
20+
|
21+
LL | 'b: for _ in 0..1 {
22+
| -- a label with a similar name exists
23+
LL |
24+
LL | break b;
25+
| ^
26+
| |
27+
| not found in this scope
28+
| help: use the similarly named label: `'b`
29+
30+
warning: unused label
31+
--> $DIR/label_misspelled_2.rs:7:5
32+
|
33+
LL | 'b: for _ in 0..1 {
34+
| ^^
35+
|
36+
note: the lint level is defined here
37+
--> $DIR/label_misspelled_2.rs:1:9
38+
|
39+
LL | #![warn(unused_labels)]
40+
| ^^^^^^^^^^^^^
41+
42+
error: aborting due to 3 previous errors; 1 warning emitted
43+
44+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)