@@ -45,42 +45,40 @@ that warns about any item named `lintme`.
45
45
extern crate rustc_ast;
46
46
47
47
// Load rustc as a plugin to get macros
48
- #[macro_use]
49
- extern crate rustc;
50
48
extern crate rustc_driver;
49
+ #[macro_use]
50
+ extern crate rustc_lint;
51
+ #[macro_use]
52
+ extern crate rustc_session;
51
53
52
- use rustc::lint::{EarlyContext, LintContext, LintPass, EarlyLintPass,
53
- EarlyLintPassObject, LintArray};
54
54
use rustc_driver::plugin::Registry;
55
+ use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
55
56
use rustc_ast::ast;
56
-
57
57
declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
58
58
59
- struct Pass;
60
-
61
- impl LintPass for Pass {
62
- fn get_lints(&self) -> LintArray {
63
- lint_array!(TEST_LINT)
64
- }
65
- }
59
+ declare_lint_pass!(Pass => [TEST_LINT]);
66
60
67
61
impl EarlyLintPass for Pass {
68
62
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
69
- if it.ident.as_str() == "lintme" {
70
- cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
63
+ if it.ident.name.as_str() == "lintme" {
64
+ cx.lint(TEST_LINT, |lint| {
65
+ lint.build("item is named 'lintme'").set_span(it.span).emit()
66
+ });
71
67
}
72
68
}
73
69
}
74
70
75
71
#[plugin_registrar]
76
72
pub fn plugin_registrar(reg: &mut Registry) {
77
- reg.register_early_lint_pass(box Pass as EarlyLintPassObject);
73
+ reg.lint_store.register_lints(&[&TEST_LINT]);
74
+ reg.lint_store.register_early_pass(|| box Pass);
78
75
}
79
76
```
80
77
81
78
Then code like
82
79
83
80
``` rust,ignore
81
+ #![feature(plugin)]
84
82
#![plugin(lint_plugin_test)]
85
83
86
84
fn lintme() { }
@@ -107,7 +105,7 @@ The components of a lint plugin are:
107
105
108
106
Lint passes are syntax traversals, but they run at a late stage of compilation
109
107
where type information is available. ` rustc ` 's [ built-in
110
- lints] ( https://github.com/rust-lang/rust/blob/master/src/librustc /lint/builtin.rs )
108
+ lints] ( https://github.com/rust-lang/rust/blob/master/src/librustc_session /lint/builtin.rs )
111
109
mostly use the same infrastructure as lint plugins, and provide examples of how
112
110
to access type information.
113
111
0 commit comments