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
#![feature(plugin_registrar)]
#![feature(rustc_private)]
extern crate syntax;
#[macro_use]
extern crate rustc;
extern crate rustc_plugin;
use rustc::lint::*;
use rustc::hir as ast;
use std::ops::Deref;
declare_lint!(DUMMY_SPAN,
Warn,
"detects uses of DUMMY_SP");
struct Pass;
impl Pass {
fn new() -> Pass {
Pass
}
}
impl LintPass for Pass {
fn get_lints(&self) -> LintArray {
lint_array!(DUMMY_SPAN)
}
fn name(&self) -> &'static str {
"syntaxext"
}
}
impl LateLintPass<'_, '_> for Pass {
fn check_expr(&mut self, cx: &LateContext, expr: &ast::Expr) {
match expr.node {
ast::ExprKind::Path(ast::QPath::Resolved(None, ref path)) => {
let ident = path.segments.last().unwrap().ident;
let name = ident.name.as_str();
if name.deref() == "DUMMY_SP" {
cx.span_lint(DUMMY_SPAN, ident.span,
"usage of 'DUMMY_SP' is discouraged");
}
},
_ => {},
}
}
}
#[plugin_registrar]
pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
reg.register_late_lint_pass(Box::new(Pass::new()) as LateLintPassObject);
}