Add tests for new labeled blocks for unused_labels

This commit is contained in:
Kyle Stachowicz 2018-05-17 17:32:05 -07:00
parent 88f4063c83
commit 702f1dd846
6 changed files with 34 additions and 15 deletions

View file

@ -9,6 +9,7 @@
// except according to those terms.
#![feature(label_break_value)]
#![allow(unused_labels)]
// Simple continue pointing to an unlabeled break should yield in an error
fn continue_simple() {

View file

@ -1,17 +1,17 @@
error[E0695]: unlabeled `continue` inside of a labeled block
--> $DIR/label_break_value_continue.rs:16:9
--> $DIR/label_break_value_continue.rs:17:9
|
LL | continue; //~ ERROR unlabeled `continue` inside of a labeled block
| ^^^^^^^^ `continue` statements that would diverge to or through a labeled block need to bear a label
error[E0696]: `continue` pointing to a labeled block
--> $DIR/label_break_value_continue.rs:23:9
--> $DIR/label_break_value_continue.rs:24:9
|
LL | continue 'b; //~ ERROR `continue` pointing to a labeled block
| ^^^^^^^^^^^ labeled blocks cannot be `continue`'d
|
note: labeled block the continue points to
--> $DIR/label_break_value_continue.rs:22:5
--> $DIR/label_break_value_continue.rs:23:5
|
LL | / 'b: {
LL | | continue 'b; //~ ERROR `continue` pointing to a labeled block
@ -19,7 +19,7 @@ LL | | }
| |_____^
error[E0695]: unlabeled `continue` inside of a labeled block
--> $DIR/label_break_value_continue.rs:31:13
--> $DIR/label_break_value_continue.rs:32:13
|
LL | continue; //~ ERROR unlabeled `continue` inside of a labeled block
| ^^^^^^^^ `continue` statements that would diverge to or through a labeled block need to bear a label

View file

@ -9,6 +9,7 @@
// except according to those terms.
#![feature(label_break_value)]
#![allow(unused_labels)]
// Simple unlabeled break should yield in an error
fn unlabeled_break_simple() {

View file

@ -1,11 +1,11 @@
error[E0695]: unlabeled `break` inside of a labeled block
--> $DIR/label_break_value_unlabeled_break.rs:16:9
--> $DIR/label_break_value_unlabeled_break.rs:17:9
|
LL | break; //~ ERROR unlabeled `break` inside of a labeled block
| ^^^^^ `break` statements that would diverge to or through a labeled block need to bear a label
error[E0695]: unlabeled `break` inside of a labeled block
--> $DIR/label_break_value_unlabeled_break.rs:24:13
--> $DIR/label_break_value_unlabeled_break.rs:25:13
|
LL | break; //~ ERROR unlabeled `break` inside of a labeled block
| ^^^^^ `break` statements that would diverge to or through a labeled block need to bear a label

View file

@ -14,6 +14,8 @@
// compile-pass
#![feature(label_break_value)]
fn main() {
'unused_while_label: while 0 == 0 {
//~^ WARN unused label
@ -67,9 +69,18 @@ fn main() {
}
}
// This is diverging, so put it at the end so we don't get
// unreachable_code errors everywhere else
'unused_loop_label: loop {
//~^ WARN unused label
break;
}
// Make sure unused block labels give warnings...
'unused_block_label: {
//~^ WARN unused label
}
// ...and that used ones don't:
'used_block_label: {
break 'used_block_label;
}
}

View file

@ -1,5 +1,5 @@
warning: unused label
--> $DIR/unused_labels.rs:18:5
--> $DIR/unused_labels.rs:20:5
|
LL | 'unused_while_label: while 0 == 0 {
| ^^^^^^^^^^^^^^^^^^^
@ -7,31 +7,31 @@ LL | 'unused_while_label: while 0 == 0 {
= note: #[warn(unused_labels)] on by default
warning: unused label
--> $DIR/unused_labels.rs:23:5
--> $DIR/unused_labels.rs:25:5
|
LL | 'unused_while_let_label: while let Some(_) = opt {
| ^^^^^^^^^^^^^^^^^^^^^^^
warning: unused label
--> $DIR/unused_labels.rs:27:5
--> $DIR/unused_labels.rs:29:5
|
LL | 'unused_for_label: for _ in 0..10 {
| ^^^^^^^^^^^^^^^^^
warning: unused label
--> $DIR/unused_labels.rs:43:9
--> $DIR/unused_labels.rs:45:9
|
LL | 'unused_loop_label_inner_2: for _ in 0..10 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: unused label
--> $DIR/unused_labels.rs:49:5
--> $DIR/unused_labels.rs:51:5
|
LL | 'unused_loop_label_outer_3: for _ in 0..10 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: unused label
--> $DIR/unused_labels.rs:58:5
--> $DIR/unused_labels.rs:60:5
|
LL | 'many_used_shadowed: for _ in 0..10 {
| ^^^^^^^^^^^^^^^^^^^
@ -42,8 +42,14 @@ warning: unused label
LL | 'unused_loop_label: loop {
| ^^^^^^^^^^^^^^^^^^
warning: unused label
--> $DIR/unused_labels.rs:78:5
|
LL | 'unused_block_label: {
| ^^^^^^^^^^^^^^^^^^^
warning: label name `'many_used_shadowed` shadows a label name that is already in scope
--> $DIR/unused_labels.rs:60:9
--> $DIR/unused_labels.rs:62:9
|
LL | 'many_used_shadowed: for _ in 0..10 {
| ------------------- first declared here