Skip to content

Commit e65d6ed

Browse files
authored
2 parents 60bf83d + 3e48848 commit e65d6ed

File tree

1 file changed

+14
-16
lines changed
  • src/doc/unstable-book/src/language-features

1 file changed

+14
-16
lines changed

src/doc/unstable-book/src/language-features/plugin.md

+14-16
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,40 @@ that warns about any item named `lintme`.
4545
extern crate rustc_ast;
4646
4747
// Load rustc as a plugin to get macros
48-
#[macro_use]
49-
extern crate rustc;
5048
extern 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};
5454
use rustc_driver::plugin::Registry;
55+
use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
5556
use rustc_ast::ast;
56-
5757
declare_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
6761
impl 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]
7672
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);
7875
}
7976
```
8077

8178
Then code like
8279

8380
```rust,ignore
81+
#![feature(plugin)]
8482
#![plugin(lint_plugin_test)]
8583
8684
fn lintme() { }
@@ -107,7 +105,7 @@ The components of a lint plugin are:
107105

108106
Lint passes are syntax traversals, but they run at a late stage of compilation
109107
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)
111109
mostly use the same infrastructure as lint plugins, and provide examples of how
112110
to access type information.
113111

0 commit comments

Comments
 (0)