X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Funused_label.rs;h=5c5550ed30fb2e675a3059f6b1d13e941a11ea37;hb=48cb6e273ea49e85b6baa209e0123a2bbd6d15c2;hp=c74554d5083b4f0de1175f4b48a44fe3fd90a6a2;hpb=49bf9762c358937a9e22091ba490b9e32acd5494;p=rust.git diff --git a/clippy_lints/src/unused_label.rs b/clippy_lints/src/unused_label.rs index c74554d5083..5c5550ed30f 100644 --- a/clippy_lints/src/unused_label.rs +++ b/clippy_lints/src/unused_label.rs @@ -1,11 +1,11 @@ use rustc::lint::*; use rustc::hir; -use rustc::hir::intravisit::{FnKind, Visitor, walk_expr, walk_fn, NestedVisitorMap}; +use rustc::hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor}; use std::collections::HashMap; use syntax::ast; use syntax::codemap::Span; -use syntax::symbol::InternedString; -use utils::{in_macro, span_lint}; +use syntax::symbol::LocalInternedString; +use crate::utils::{in_macro, span_lint}; /// **What it does:** Checks for unused labels. /// @@ -21,16 +21,16 @@ /// if i > 4 { continue } /// } /// ``` -declare_lint! { +declare_clippy_lint! { pub UNUSED_LABEL, - Warn, + complexity, "unused labels" } pub struct UnusedLabel; struct UnusedLabelVisitor<'a, 'tcx: 'a> { - labels: HashMap, + labels: HashMap, cx: &'a LateContext<'a, 'tcx>, } @@ -48,14 +48,14 @@ fn check_fn( decl: &'tcx hir::FnDecl, body: &'tcx hir::Body, span: Span, - fn_id: ast::NodeId + fn_id: ast::NodeId, ) { - if in_macro(cx, span) { + if in_macro(span) { return; } let mut v = UnusedLabelVisitor { - cx: cx, + cx, labels: HashMap::new(), }; walk_fn(&mut v, kind, decl, body.id(), span, fn_id); @@ -69,13 +69,11 @@ fn check_fn( impl<'a, 'tcx: 'a> Visitor<'tcx> for UnusedLabelVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx hir::Expr) { match expr.node { - hir::ExprBreak(Some(label), _) | - hir::ExprAgain(Some(label)) => { - self.labels.remove(&label.name.as_str()); + hir::ExprBreak(destination, _) | hir::ExprContinue(destination) => if let Some(label) = destination.label { + self.labels.remove(&label.ident.as_str()); }, - hir::ExprLoop(_, Some(label), _) | - hir::ExprWhile(_, _, Some(label)) => { - self.labels.insert(label.node.as_str(), expr.span); + hir::ExprLoop(_, Some(label), _) | hir::ExprWhile(_, _, Some(label)) => { + self.labels.insert(label.ident.as_str(), expr.span); }, _ => (), }