]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/unused_label.rs
Rustup
[rust.git] / clippy_lints / src / unused_label.rs
index 6f91b873a480cf4487a14cb7d8ee7ed96f004f5f..5c5550ed30fb2e675a3059f6b1d13e941a11ea37 100644 (file)
@@ -4,8 +4,8 @@
 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.
 ///
 ///         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<InternedString, Span>,
+    labels: HashMap<LocalInternedString, Span>,
     cx: &'a LateContext<'a, 'tcx>,
 }
 
@@ -55,7 +55,7 @@ fn check_fn(
         }
 
         let mut v = UnusedLabelVisitor {
-            cx: cx,
+            cx,
             labels: HashMap::new(),
         };
         walk_fn(&mut v, kind, decl, body.id(), span, fn_id);
@@ -69,11 +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(destination, _) | hir::ExprAgain(destination) => if let Some(label) = destination.ident {
-                self.labels.remove(&label.node.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);
+                self.labels.insert(label.ident.as_str(), expr.span);
             },
             _ => (),
         }