]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/enum_glob_use.rs
Merge branch 'macro-use' into HEAD
[rust.git] / clippy_lints / src / enum_glob_use.rs
index 4dafcf365a6c6b4ffe69b0bec724531fad9913cf..10cf497725c5306efbe1d152198e84cfe60aeb37 100644 (file)
@@ -1,10 +1,12 @@
 //! lint on `use`ing all variants of an enum
 
 use rustc::hir::*;
-use rustc::lint::{LateLintPass, LintPass, LateContext, LintArray};
+use rustc::hir::def::Def;
+use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::{declare_lint, lint_array};
 use syntax::ast::NodeId;
 use syntax::codemap::Span;
-use utils::span_lint;
+use crate::utils::span_lint;
 
 /// **What it does:** Checks for `use Enum::*`.
 ///
@@ -18,9 +20,9 @@
 /// ```rust
 /// use std::cmp::Ordering::*;
 /// ```
-declare_lint! {
+declare_clippy_lint! {
     pub ENUM_GLOB_USE,
-    Allow,
+    pedantic,
     "use items that import all variants of an enum"
 }
 
@@ -36,22 +38,24 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse {
     fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: NodeId) {
         // only check top level `use` statements
         for item in &m.item_ids {
-            self.lint_item(cx, cx.krate.item(item.id));
+            self.lint_item(cx, cx.tcx.hir.expect_item(item.id));
         }
     }
 }
 
 impl EnumGlobUse {
     fn lint_item(&self, cx: &LateContext, item: &Item) {
-        if item.vis == Visibility::Public {
+        if item.vis.node.is_pub() {
             return; // re-exports are fine
         }
-        if let ItemUse(ref path, UseKind::Glob) = item.node {
-            // FIXME: ask jseyfried why the qpath.def for `use std::cmp::Ordering::*;`
-            // extracted through `ItemUse(ref qpath, UseKind::Glob)` is a `Mod` and not an `Enum`
-            //if let Def::Enum(_) = path.def {
-            if path.segments.last().and_then(|seg| seg.name.as_str().chars().next()).map_or(false, char::is_uppercase) {
-                span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
+        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",
+                );
             }
         }
     }