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:
commit
19dbb22032
11 changed files with 26 additions and 167 deletions
|
|
@ -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`"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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::<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),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue