1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use rustc::hir::*;
use rustc::lint::{LateLintPass, LintPass, LateContext, LintArray};
use syntax::ast::NodeId;
use syntax::codemap::Span;
use utils::span_lint;
declare_lint! {
pub ENUM_GLOB_USE,
Allow,
"use items that import all variants of an enum"
}
pub struct EnumGlobUse;
impl LintPass for EnumGlobUse {
fn get_lints(&self) -> LintArray {
lint_array!(ENUM_GLOB_USE)
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse {
fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: NodeId) {
for item in &m.item_ids {
self.lint_item(cx, cx.krate.item(item.id));
}
}
}
impl EnumGlobUse {
fn lint_item(&self, cx: &LateContext, item: &Item) {
if item.vis == Visibility::Public {
return;
}
if let ItemUse(ref path, UseKind::Glob) = item.node {
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");
}
}
}
}