@@ -45,42 +45,40 @@ that warns about any item named `lintme`.
4545extern crate rustc_ast;
4646
4747// Load rustc as a plugin to get macros
48- #[macro_use]
49- extern crate rustc;
5048extern crate rustc_driver;
49+ #[macro_use]
50+ extern crate rustc_lint;
51+ #[macro_use]
52+ extern crate rustc_session;
5153
52- use rustc::lint::{EarlyContext, LintContext, LintPass, EarlyLintPass,
53- EarlyLintPassObject, LintArray};
5454use rustc_driver::plugin::Registry;
55+ use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
5556use rustc_ast::ast;
56-
5757declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
5858
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]);
6660
6761impl EarlyLintPass for Pass {
6862 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+ });
7167 }
7268 }
7369}
7470
7571#[plugin_registrar]
7672pub 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);
7875}
7976```
8077
8178Then code like
8279
8380``` rust,ignore
81+ #![feature(plugin)]
8482#![plugin(lint_plugin_test)]
8583
8684fn lintme() { }
@@ -107,7 +105,7 @@ The components of a lint plugin are:
107105
108106Lint passes are syntax traversals, but they run at a late stage of compilation
109107where 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 )
111109mostly use the same infrastructure as lint plugins, and provide examples of how
112110to access type information.
113111
0 commit comments