From 710c749bb12bc84018e04b63424b8d8d3d80a9c4 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 21 Dec 2019 16:20:30 +0100 Subject: [PATCH] Deprecate unused_label lint This lint was uplifted/turned into warn-by-default in rustc --- README.md | 2 +- clippy_lints/src/deprecated_lints.rs | 9 +++ clippy_lints/src/lib.rs | 9 ++- clippy_lints/src/unused_label.rs | 83 ---------------------------- src/lintlist/mod.rs | 9 +-- tests/ui/deprecated.rs | 1 + tests/ui/deprecated.stderr | 8 ++- tests/ui/empty_loop.rs | 1 - tests/ui/empty_loop.stderr | 6 +- tests/ui/unused_labels.rs | 35 ------------ tests/ui/unused_labels.stderr | 30 ---------- 11 files changed, 26 insertions(+), 167 deletions(-) delete mode 100644 clippy_lints/src/unused_label.rs delete mode 100644 tests/ui/unused_labels.rs delete mode 100644 tests/ui/unused_labels.stderr diff --git a/README.md b/README.md index 6133fa4c3a57..97a7c97b49a2 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index f399b4a78c6d..93c19bf95506 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -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`" +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 7fb499ebf855..d4e86cbfe57a 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -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, it’s used in `update_lints` // begin register lints, do not remove this comment, it’s 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::>(); 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), ]); diff --git a/clippy_lints/src/unused_label.rs b/clippy_lints/src/unused_label.rs deleted file mode 100644 index 60acbc1469f9..000000000000 --- a/clippy_lints/src/unused_label.rs +++ /dev/null @@ -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, - 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()) - } -} diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index c91be11f4f40..f3012fba2da0 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s 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", diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs index 91d43758ab0a..188a641aa1af 100644 --- a/tests/ui/deprecated.rs +++ b/tests/ui/deprecated.rs @@ -6,5 +6,6 @@ #[warn(clippy::unused_collect)] #[warn(clippy::invalid_ref)] #[warn(clippy::into_iter_on_array)] +#[warn(clippy::unused_label)] fn main() {} diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index d353b26e5376..a4efe3d15a95 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -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 diff --git a/tests/ui/empty_loop.rs b/tests/ui/empty_loop.rs index fb9f2cb9cf41..8fd7697eb3b2 100644 --- a/tests/ui/empty_loop.rs +++ b/tests/ui/empty_loop.rs @@ -1,7 +1,6 @@ // aux-build:macro_rules.rs #![warn(clippy::empty_loop)] -#![allow(clippy::unused_label)] #[macro_use] extern crate macro_rules; diff --git a/tests/ui/empty_loop.stderr b/tests/ui/empty_loop.stderr index 41b799004251..e44c58ea770a 100644 --- a/tests/ui/empty_loop.stderr +++ b/tests/ui/empty_loop.stderr @@ -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 {} | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/unused_labels.rs b/tests/ui/unused_labels.rs deleted file mode 100644 index ae963ad6969f..000000000000 --- a/tests/ui/unused_labels.rs +++ /dev/null @@ -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; - } -} diff --git a/tests/ui/unused_labels.stderr b/tests/ui/unused_labels.stderr deleted file mode 100644 index d2ca0f1b57f0..000000000000 --- a/tests/ui/unused_labels.stderr +++ /dev/null @@ -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 -