about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2015-10-15 23:53:05 +0200
committerFlorian Hahn <flo@fhahn.com>2015-10-15 23:53:05 +0200
commitac097f1a5efb735e852883e841ee3a5cfbc26d0b (patch)
treecd9ce402bdc9d72875d5d0e9f15fdcbea6a75a6e
parentbe3d390cf51545b880c5cd78585fa408c087f786 (diff)
downloadrust-ac097f1a5efb735e852883e841ee3a5cfbc26d0b.tar.gz
rust-ac097f1a5efb735e852883e841ee3a5cfbc26d0b.zip
Update lint plugin example in book to work with recent master
-rw-r--r--src/doc/trpl/compiler-plugins.md30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/doc/trpl/compiler-plugins.md b/src/doc/trpl/compiler-plugins.md
index ffa8be5ac08..e1c98251117 100644
--- a/src/doc/trpl/compiler-plugins.md
+++ b/src/doc/trpl/compiler-plugins.md
@@ -170,13 +170,25 @@ starting point for an improved quasiquote as an ordinary plugin library.
 
 Plugins can extend [Rust's lint
 infrastructure](../reference.html#lint-check-attributes) with additional checks for
-code style, safety, etc. You can see
-[`src/test/auxiliary/lint_plugin_test.rs`](https://github.com/rust-lang/rust/blob/master/src/test/auxiliary/lint_plugin_test.rs)
-for a full example, the core of which is reproduced here:
+code style, safety, etc. Now let's write a plugin [`lint_plugin_test.rs`](https://github.com/rust-lang/rust/blob/master/src/test/auxiliary/lint_plugin_test.rs)
+that warns about any item named `lintme`.
 
 ```ignore
-declare_lint!(TEST_LINT, Warn,
-              "Warn about items named 'lintme'");
+#![feature(plugin_registrar)]
+#![feature(box_syntax, rustc_private)]
+
+extern crate syntax;
+
+// Load rustc as a plugin to get macros
+#[macro_use]
+extern crate rustc;
+
+use rustc::lint::{EarlyContext, LintContext, LintPass, EarlyLintPass,
+                  EarlyLintPassObject, LintArray};
+use rustc::plugin::Registry;
+use syntax::ast;
+
+declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
 
 struct Pass;
 
@@ -184,9 +196,11 @@ impl LintPass for Pass {
     fn get_lints(&self) -> LintArray {
         lint_array!(TEST_LINT)
     }
+}
 
-    fn check_item(&mut self, cx: &Context, it: &ast::Item) {
-        if it.ident.name == "lintme" {
+impl EarlyLintPass for Pass {
+    fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
+        if it.ident.name.as_str() == "lintme" {
             cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
         }
     }
@@ -194,7 +208,7 @@ impl LintPass for Pass {
 
 #[plugin_registrar]
 pub fn plugin_registrar(reg: &mut Registry) {
-    reg.register_lint_pass(box Pass as LintPassObject);
+    reg.register_early_lint_pass(box Pass as EarlyLintPassObject);
 }
 ```