1 //! lint on `use`ing all variants of an enum
4 use rustc::hir::def::Def;
5 use rustc::lint::{LateLintPass, LintPass, LateContext, LintArray};
6 use syntax::ast::NodeId;
7 use syntax::codemap::Span;
10 /// **What it does:** Checks for `use Enum::*`.
12 /// **Why is this bad?** It is usually better style to use the prefixed name of
13 /// an enumeration variant, rather than importing variants.
15 /// **Known problems:** Old-style enumerations that prefix the variants are
20 /// use std::cmp::Ordering::*;
25 "use items that import all variants of an enum"
28 pub struct EnumGlobUse;
30 impl LintPass for EnumGlobUse {
31 fn get_lints(&self) -> LintArray {
32 lint_array!(ENUM_GLOB_USE)
36 impl LateLintPass for EnumGlobUse {
37 fn check_mod(&mut self, cx: &LateContext, m: &Mod, _: Span, _: NodeId) {
38 // only check top level `use` statements
39 for item in &m.item_ids {
40 self.lint_item(cx, cx.krate.item(item.id));
46 fn lint_item(&self, cx: &LateContext, item: &Item) {
47 if item.vis == Visibility::Public {
48 return; // re-exports are fine
50 if let ItemUse(ref path, UseKind::Glob) = item.node {
51 if let Def::Enum(_) = path.def {
52 span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");