]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/enum_glob_use.rs
Auto merge of #3946 - rchaser53:issue-3920, r=flip1995
[rust.git] / clippy_lints / src / enum_glob_use.rs
index 042a4765e2b73bb1781b9f52f0f8bd73d878c971..afdf27376d8047898981de388fac65b3751cd132 100644 (file)
@@ -1,26 +1,25 @@
 //! lint on `use`ing all variants of an enum
 
-use rustc::hir::*;
+use crate::utils::span_lint;
 use rustc::hir::def::Def;
+use rustc::hir::*;
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
 use rustc::{declare_tool_lint, lint_array};
-use syntax::ast::NodeId;
 use syntax::source_map::Span;
-use crate::utils::span_lint;
 
-/// **What it does:** Checks for `use Enum::*`.
-///
-/// **Why is this bad?** It is usually better style to use the prefixed name of
-/// an enumeration variant, rather than importing variants.
-///
-/// **Known problems:** Old-style enumerations that prefix the variants are
-/// still around.
-///
-/// **Example:**
-/// ```rust
-/// use std::cmp::Ordering::*;
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for `use Enum::*`.
+    ///
+    /// **Why is this bad?** It is usually better style to use the prefixed name of
+    /// an enumeration variant, rather than importing variants.
+    ///
+    /// **Known problems:** Old-style enumerations that prefix the variants are
+    /// still around.
+    ///
+    /// **Example:**
+    /// ```rust
+    /// use std::cmp::Ordering::*;
+    /// ```
     pub ENUM_GLOB_USE,
     pedantic,
     "use items that import all variants of an enum"
@@ -32,13 +31,18 @@ impl LintPass for EnumGlobUse {
     fn get_lints(&self) -> LintArray {
         lint_array!(ENUM_GLOB_USE)
     }
+
+    fn name(&self) -> &'static str {
+        "EnumGlobUse"
+    }
 }
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse {
-    fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: NodeId) {
+    fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: HirId) {
+        let map = cx.tcx.hir();
         // only check top level `use` statements
         for item in &m.item_ids {
-            self.lint_item(cx, cx.tcx.hir.expect_item(item.id));
+            self.lint_item(cx, map.expect_item(map.hir_to_node_id(item.id)));
         }
     }
 }
@@ -50,12 +54,7 @@ fn lint_item(&self, cx: &LateContext<'_, '_>, item: &Item) {
         }
         if let ItemKind::Use(ref path, UseKind::Glob) = item.node {
             if let Def::Enum(_) = path.def {
-                span_lint(
-                    cx,
-                    ENUM_GLOB_USE,
-                    item.span,
-                    "don't use glob imports for enum variants",
-                );
+                span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
             }
         }
     }