diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 71eefec2210e4..79b4ec61bd081 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -281,7 +281,7 @@ declare_lint! { declare_lint! { pub UNUSED_LABELS, - Warn, + Allow, "detects labels that are never used" } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 0ae133640fad9..69825027b052b 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -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, diff --git a/src/test/ui/lint/unused_labels.rs b/src/test/ui/lint/unused_labels.rs index 22b7ad4e6a7c9..23add604da6ab 100644 --- a/src/test/ui/lint/unused_labels.rs +++ b/src/test/ui/lint/unused_labels.rs @@ -15,6 +15,7 @@ // compile-pass #![feature(label_break_value)] +#![warn(unused_labels)] fn main() { 'unused_while_label: while 0 == 0 { @@ -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 { diff --git a/src/test/ui/lint/unused_labels.stderr b/src/test/ui/lint/unused_labels.stderr index d09209853e3a3..825f5e281f0b9 100644 --- a/src/test/ui/lint/unused_labels.stderr +++ b/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