Skip to content

Commit 702f1dd

Browse files
committed
Add tests for new labeled blocks for unused_labels
1 parent 88f4063 commit 702f1dd

6 files changed

+34
-15
lines changed

src/test/ui/label_break_value_continue.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(label_break_value)]
12+
#![allow(unused_labels)]
1213

1314
// Simple continue pointing to an unlabeled break should yield in an error
1415
fn continue_simple() {

src/test/ui/label_break_value_continue.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error[E0695]: unlabeled `continue` inside of a labeled block
2-
--> $DIR/label_break_value_continue.rs:16:9
2+
--> $DIR/label_break_value_continue.rs:17:9
33
|
44
LL | continue; //~ ERROR unlabeled `continue` inside of a labeled block
55
| ^^^^^^^^ `continue` statements that would diverge to or through a labeled block need to bear a label
66

77
error[E0696]: `continue` pointing to a labeled block
8-
--> $DIR/label_break_value_continue.rs:23:9
8+
--> $DIR/label_break_value_continue.rs:24:9
99
|
1010
LL | continue 'b; //~ ERROR `continue` pointing to a labeled block
1111
| ^^^^^^^^^^^ labeled blocks cannot be `continue`'d
1212
|
1313
note: labeled block the continue points to
14-
--> $DIR/label_break_value_continue.rs:22:5
14+
--> $DIR/label_break_value_continue.rs:23:5
1515
|
1616
LL | / 'b: {
1717
LL | | continue 'b; //~ ERROR `continue` pointing to a labeled block
1818
LL | | }
1919
| |_____^
2020

2121
error[E0695]: unlabeled `continue` inside of a labeled block
22-
--> $DIR/label_break_value_continue.rs:31:13
22+
--> $DIR/label_break_value_continue.rs:32:13
2323
|
2424
LL | continue; //~ ERROR unlabeled `continue` inside of a labeled block
2525
| ^^^^^^^^ `continue` statements that would diverge to or through a labeled block need to bear a label

src/test/ui/label_break_value_unlabeled_break.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(label_break_value)]
12+
#![allow(unused_labels)]
1213

1314
// Simple unlabeled break should yield in an error
1415
fn unlabeled_break_simple() {

src/test/ui/label_break_value_unlabeled_break.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0695]: unlabeled `break` inside of a labeled block
2-
--> $DIR/label_break_value_unlabeled_break.rs:16:9
2+
--> $DIR/label_break_value_unlabeled_break.rs:17:9
33
|
44
LL | break; //~ ERROR unlabeled `break` inside of a labeled block
55
| ^^^^^ `break` statements that would diverge to or through a labeled block need to bear a label
66

77
error[E0695]: unlabeled `break` inside of a labeled block
8-
--> $DIR/label_break_value_unlabeled_break.rs:24:13
8+
--> $DIR/label_break_value_unlabeled_break.rs:25:13
99
|
1010
LL | break; //~ ERROR unlabeled `break` inside of a labeled block
1111
| ^^^^^ `break` statements that would diverge to or through a labeled block need to bear a label

src/test/ui/lint/unused_labels.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
// compile-pass
1616

17+
#![feature(label_break_value)]
18+
1719
fn main() {
1820
'unused_while_label: while 0 == 0 {
1921
//~^ WARN unused label
@@ -67,9 +69,18 @@ fn main() {
6769
}
6870
}
6971

70-
// This is diverging, so put it at the end so we don't get
71-
// unreachable_code errors everywhere else
7272
'unused_loop_label: loop {
7373
//~^ WARN unused label
74+
break;
75+
}
76+
77+
// Make sure unused block labels give warnings...
78+
'unused_block_label: {
79+
//~^ WARN unused label
80+
}
81+
82+
// ...and that used ones don't:
83+
'used_block_label: {
84+
break 'used_block_label;
7485
}
7586
}

src/test/ui/lint/unused_labels.stderr

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
warning: unused label
2-
--> $DIR/unused_labels.rs:18:5
2+
--> $DIR/unused_labels.rs:20:5
33
|
44
LL | 'unused_while_label: while 0 == 0 {
55
| ^^^^^^^^^^^^^^^^^^^
66
|
77
= note: #[warn(unused_labels)] on by default
88

99
warning: unused label
10-
--> $DIR/unused_labels.rs:23:5
10+
--> $DIR/unused_labels.rs:25:5
1111
|
1212
LL | 'unused_while_let_label: while let Some(_) = opt {
1313
| ^^^^^^^^^^^^^^^^^^^^^^^
1414

1515
warning: unused label
16-
--> $DIR/unused_labels.rs:27:5
16+
--> $DIR/unused_labels.rs:29:5
1717
|
1818
LL | 'unused_for_label: for _ in 0..10 {
1919
| ^^^^^^^^^^^^^^^^^
2020

2121
warning: unused label
22-
--> $DIR/unused_labels.rs:43:9
22+
--> $DIR/unused_labels.rs:45:9
2323
|
2424
LL | 'unused_loop_label_inner_2: for _ in 0..10 {
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
2626

2727
warning: unused label
28-
--> $DIR/unused_labels.rs:49:5
28+
--> $DIR/unused_labels.rs:51:5
2929
|
3030
LL | 'unused_loop_label_outer_3: for _ in 0..10 {
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
3232

3333
warning: unused label
34-
--> $DIR/unused_labels.rs:58:5
34+
--> $DIR/unused_labels.rs:60:5
3535
|
3636
LL | 'many_used_shadowed: for _ in 0..10 {
3737
| ^^^^^^^^^^^^^^^^^^^
@@ -42,8 +42,14 @@ warning: unused label
4242
LL | 'unused_loop_label: loop {
4343
| ^^^^^^^^^^^^^^^^^^
4444

45+
warning: unused label
46+
--> $DIR/unused_labels.rs:78:5
47+
|
48+
LL | 'unused_block_label: {
49+
| ^^^^^^^^^^^^^^^^^^^
50+
4551
warning: label name `'many_used_shadowed` shadows a label name that is already in scope
46-
--> $DIR/unused_labels.rs:60:9
52+
--> $DIR/unused_labels.rs:62:9
4753
|
4854
LL | 'many_used_shadowed: for _ in 0..10 {
4955
| ------------------- first declared here

0 commit comments

Comments
 (0)