Auto merge of #4930 - flip1995:unused_label, r=phansch

Deprecate unused_label lint

This lint was uplifted/turned into warn-by-default in rustc

Fixes #4925

changelog: Deprecate [`unused_label`] lint
This commit is contained in:
bors 2019-12-22 09:39:32 +00:00
commit 19dbb22032
11 changed files with 26 additions and 167 deletions

View File

@ -6,7 +6,7 @@
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
[There are 340 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
[There are 339 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:

View File

@ -138,3 +138,12 @@ declare_deprecated_lint! {
pub INTO_ITER_ON_ARRAY,
"this lint has been uplifted to rustc and is now called `array_into_iter`"
}
declare_deprecated_lint! {
/// **What it does:** Nothing. This lint has been deprecated.
///
/// **Deprecation reason:** This lint has been uplifted to rustc and is now called
/// `unused_labels`.
pub UNUSED_LABEL,
"this lint has been uplifted to rustc and is now called `unused_labels`"
}

View File

@ -292,7 +292,6 @@ pub mod types;
pub mod unicode;
pub mod unsafe_removed_from_name;
pub mod unused_io_amount;
pub mod unused_label;
pub mod unused_self;
pub mod unwrap;
pub mod use_self;
@ -446,6 +445,10 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
"clippy::into_iter_on_array",
"this lint has been uplifted to rustc and is now called `array_into_iter`",
);
store.register_removed(
"clippy::unused_label",
"this lint has been uplifted to rustc and is now called `unused_labels`",
);
// end deprecated lints, do not remove this comment, its used in `update_lints`
// begin register lints, do not remove this comment, its used in `update_lints`
@ -774,7 +777,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
&unicode::ZERO_WIDTH_SPACE,
&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
&unused_io_amount::UNUSED_IO_AMOUNT,
&unused_label::UNUSED_LABEL,
&unused_self::UNUSED_SELF,
&unwrap::PANICKING_UNWRAP,
&unwrap::UNNECESSARY_UNWRAP,
@ -868,7 +870,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
store.register_late_pass(|| box format::UselessFormat);
store.register_late_pass(|| box swap::Swap);
store.register_late_pass(|| box overflow_check_conditional::OverflowCheckConditional);
store.register_late_pass(|| box unused_label::UnusedLabel);
store.register_late_pass(|| box new_without_default::NewWithoutDefault::default());
let blacklisted_names = conf.blacklisted_names.iter().cloned().collect::<FxHashSet<_>>();
store.register_late_pass(move || box blacklisted_name::BlacklistedName::new(blacklisted_names.clone()));
@ -1302,7 +1303,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
LintId::of(&unicode::ZERO_WIDTH_SPACE),
LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME),
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),
LintId::of(&unused_label::UNUSED_LABEL),
LintId::of(&unwrap::PANICKING_UNWRAP),
LintId::of(&unwrap::UNNECESSARY_UNWRAP),
LintId::of(&vec::USELESS_VEC),
@ -1482,7 +1482,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
LintId::of(&types::UNIT_ARG),
LintId::of(&types::UNNECESSARY_CAST),
LintId::of(&types::VEC_BOX),
LintId::of(&unused_label::UNUSED_LABEL),
LintId::of(&unwrap::UNNECESSARY_UNWRAP),
LintId::of(&zero_div_zero::ZERO_DIVIDED_BY_ZERO),
]);

View File

@ -1,83 +0,0 @@
use crate::utils::span_lint;
use rustc::declare_lint_pass;
use rustc::hir;
use rustc::hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc_data_structures::fx::FxHashMap;
use rustc_session::declare_tool_lint;
use syntax::source_map::Span;
use syntax::symbol::Symbol;
declare_clippy_lint! {
/// **What it does:** Checks for unused labels.
///
/// **Why is this bad?** Maybe the label should be used in which case there is
/// an error in the code or it should be removed.
///
/// **Known problems:** Hopefully none.
///
/// **Example:**
/// ```rust,ignore
/// fn unused_label() {
/// 'label: for i in 1..2 {
/// if i > 4 { continue }
/// }
/// ```
pub UNUSED_LABEL,
complexity,
"unused labels"
}
struct UnusedLabelVisitor<'a, 'tcx> {
labels: FxHashMap<Symbol, Span>,
cx: &'a LateContext<'a, 'tcx>,
}
declare_lint_pass!(UnusedLabel => [UNUSED_LABEL]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedLabel {
fn check_fn(
&mut self,
cx: &LateContext<'a, 'tcx>,
kind: FnKind<'tcx>,
decl: &'tcx hir::FnDecl,
body: &'tcx hir::Body,
span: Span,
fn_id: hir::HirId,
) {
if span.from_expansion() {
return;
}
let mut v = UnusedLabelVisitor {
cx,
labels: FxHashMap::default(),
};
walk_fn(&mut v, kind, decl, body.id(), span, fn_id);
for (label, span) in v.labels {
span_lint(cx, UNUSED_LABEL, span, &format!("unused label `{}`", label));
}
}
}
impl<'a, 'tcx> Visitor<'tcx> for UnusedLabelVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
match expr.kind {
hir::ExprKind::Break(destination, _) | hir::ExprKind::Continue(destination) => {
if let Some(label) = destination.label {
self.labels.remove(&label.ident.name);
}
},
hir::ExprKind::Loop(_, Some(label), _) => {
self.labels.insert(label.ident.name, expr.span);
},
_ => (),
}
walk_expr(self, expr);
}
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::All(&self.cx.tcx.hir())
}
}

View File

@ -6,7 +6,7 @@ pub use lint::Lint;
pub use lint::LINT_LEVELS;
// begin lint list, do not remove this comment, its used in `update_lints`
pub const ALL_LINTS: [Lint; 340] = [
pub const ALL_LINTS: [Lint; 339] = [
Lint {
name: "absurd_extreme_comparisons",
group: "correctness",
@ -2177,13 +2177,6 @@ pub const ALL_LINTS: [Lint; 340] = [
deprecation: None,
module: "unused_io_amount",
},
Lint {
name: "unused_label",
group: "complexity",
desc: "unused labels",
deprecation: None,
module: "unused_label",
},
Lint {
name: "unused_self",
group: "pedantic",

View File

@ -6,5 +6,6 @@
#[warn(clippy::unused_collect)]
#[warn(clippy::invalid_ref)]
#[warn(clippy::into_iter_on_array)]
#[warn(clippy::unused_label)]
fn main() {}

View File

@ -48,11 +48,17 @@ error: lint `clippy::into_iter_on_array` has been removed: `this lint has been u
LL | #[warn(clippy::into_iter_on_array)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: lint `clippy::unused_label` has been removed: `this lint has been uplifted to rustc and is now called `unused_labels``
--> $DIR/deprecated.rs:9:8
|
LL | #[warn(clippy::unused_label)]
| ^^^^^^^^^^^^^^^^^^^^
error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon`
--> $DIR/deprecated.rs:1:8
|
LL | #[warn(clippy::str_to_string)]
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 9 previous errors
error: aborting due to 10 previous errors

View File

@ -1,7 +1,6 @@
// aux-build:macro_rules.rs
#![warn(clippy::empty_loop)]
#![allow(clippy::unused_label)]
#[macro_use]
extern crate macro_rules;

View File

@ -1,5 +1,5 @@
error: empty `loop {}` detected. You may want to either use `panic!()` or add `std::thread::sleep(..);` to the loop body.
--> $DIR/empty_loop.rs:10:5
--> $DIR/empty_loop.rs:9:5
|
LL | loop {}
| ^^^^^^^
@ -7,13 +7,13 @@ LL | loop {}
= note: `-D clippy::empty-loop` implied by `-D warnings`
error: empty `loop {}` detected. You may want to either use `panic!()` or add `std::thread::sleep(..);` to the loop body.
--> $DIR/empty_loop.rs:12:9
--> $DIR/empty_loop.rs:11:9
|
LL | loop {}
| ^^^^^^^
error: empty `loop {}` detected. You may want to either use `panic!()` or add `std::thread::sleep(..);` to the loop body.
--> $DIR/empty_loop.rs:16:9
--> $DIR/empty_loop.rs:15:9
|
LL | 'inner: loop {}
| ^^^^^^^^^^^^^^^

View File

@ -1,35 +0,0 @@
#![allow(dead_code, clippy::items_after_statements, clippy::never_loop)]
#![warn(clippy::unused_label)]
fn unused_label() {
'label: for i in 1..2 {
if i > 4 {
continue;
}
}
}
fn foo() {
'same_label_in_two_fns: loop {
break 'same_label_in_two_fns;
}
}
fn bla() {
'a: loop {
break;
}
fn blub() {}
}
fn main() {
'a: for _ in 0..10 {
while let Some(42) = None {
continue 'a;
}
}
'same_label_in_two_fns: loop {
let _ = 1;
}
}

View File

@ -1,30 +0,0 @@
error: unused label `'label`
--> $DIR/unused_labels.rs:5:5
|
LL | / 'label: for i in 1..2 {
LL | | if i > 4 {
LL | | continue;
LL | | }
LL | | }
| |_____^
|
= note: `-D clippy::unused-label` implied by `-D warnings`
error: unused label `'a`
--> $DIR/unused_labels.rs:19:5
|
LL | / 'a: loop {
LL | | break;
LL | | }
| |_____^
error: unused label `'same_label_in_two_fns`
--> $DIR/unused_labels.rs:32:5
|
LL | / 'same_label_in_two_fns: loop {
LL | | let _ = 1;
LL | | }
| |_____^
error: aborting due to 3 previous errors