Skip to content

Commit

Permalink
Default unused_labels to allow, move to "unused"
Browse files Browse the repository at this point in the history
  • Loading branch information
kylestach committed May 18, 2018
1 parent 5586cd8 commit 6da64a7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/librustc/lint/builtin.rs
Expand Up @@ -281,7 +281,7 @@ declare_lint! {

declare_lint! {
pub UNUSED_LABELS,
Warn,
Allow,
"detects labels that are never used"
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc_lint/lib.rs
Expand Up @@ -177,6 +177,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UNUSED_DOC_COMMENT,
UNUSED_EXTERN_CRATES,
UNUSED_FEATURES,
UNUSED_LABELS,
UNUSED_PARENS);

add_lint_group!(sess,
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/lint/unused_labels.rs
Expand Up @@ -15,6 +15,7 @@
// compile-pass

#![feature(label_break_value)]
#![warn(unused_labels)]

fn main() {
'unused_while_label: while 0 == 0 {
Expand Down Expand Up @@ -55,6 +56,15 @@ fn main() {
}
}

// You should be able to break the same label many times
'many_used: loop {
if true {
break 'many_used;
} else {
break 'many_used;
}
}

// Test breaking many times with the same inner label doesn't break the
// warning on the outer label
'many_used_shadowed: for _ in 0..10 {
Expand Down
24 changes: 14 additions & 10 deletions src/test/ui/lint/unused_labels.stderr
@@ -1,55 +1,59 @@
warning: unused label
--> $DIR/unused_labels.rs:20:5
--> $DIR/unused_labels.rs:21:5
|
LL | 'unused_while_label: while 0 == 0 {
| ^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(unused_labels)] on by default
note: lint level defined here
--> $DIR/unused_labels.rs:18:9
|
LL | #![warn(unused_labels)]
| ^^^^^^^^^^^^^

warning: unused label
--> $DIR/unused_labels.rs:25:5
--> $DIR/unused_labels.rs:26:5
|
LL | 'unused_while_let_label: while let Some(_) = opt {
| ^^^^^^^^^^^^^^^^^^^^^^^

warning: unused label
--> $DIR/unused_labels.rs:29:5
--> $DIR/unused_labels.rs:30:5
|
LL | 'unused_for_label: for _ in 0..10 {
| ^^^^^^^^^^^^^^^^^

warning: unused label
--> $DIR/unused_labels.rs:45:9
--> $DIR/unused_labels.rs:46:9
|
LL | 'unused_loop_label_inner_2: for _ in 0..10 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: unused label
--> $DIR/unused_labels.rs:51:5
--> $DIR/unused_labels.rs:52:5
|
LL | 'unused_loop_label_outer_3: for _ in 0..10 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: unused label
--> $DIR/unused_labels.rs:60:5
--> $DIR/unused_labels.rs:70:5
|
LL | 'many_used_shadowed: for _ in 0..10 {
| ^^^^^^^^^^^^^^^^^^^

warning: unused label
--> $DIR/unused_labels.rs:72:5
--> $DIR/unused_labels.rs:82:5
|
LL | 'unused_loop_label: loop {
| ^^^^^^^^^^^^^^^^^^

warning: unused label
--> $DIR/unused_labels.rs:78:5
--> $DIR/unused_labels.rs:88:5
|
LL | 'unused_block_label: {
| ^^^^^^^^^^^^^^^^^^^

warning: label name `'many_used_shadowed` shadows a label name that is already in scope
--> $DIR/unused_labels.rs:62:9
--> $DIR/unused_labels.rs:72:9
|
LL | 'many_used_shadowed: for _ in 0..10 {
| ------------------- first declared here
Expand Down

0 comments on commit 6da64a7

Please sign in to comment.