1 #![feature(plugin_registrar)]
2 #![feature(box_syntax, rustc_private)]
4 extern crate rustc_ast;
6 // Load rustc as a plugin to get macros
7 extern crate rustc_driver;
9 extern crate rustc_lint;
11 extern crate rustc_session;
13 use rustc_driver::plugin::Registry;
14 use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintId, LintPass};
16 declare_tool_lint!(pub clippy::TEST_LINT, Warn, "Warn about stuff");
19 pub clippy::TEST_GROUP,
20 Warn, "Warn about other stuff"
25 pub rustc::TEST_RUSTC_TOOL_LINT,
30 declare_lint_pass!(Pass => [TEST_LINT, TEST_GROUP, TEST_RUSTC_TOOL_LINT]);
32 impl EarlyLintPass for Pass {
33 fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
34 if it.ident.name.as_str() == "lintme" {
35 cx.lint(TEST_LINT, |lint| {
36 lint.build("item is named 'lintme'").set_span(it.span).emit()
39 if it.ident.name.as_str() == "lintmetoo" {
40 cx.lint(TEST_GROUP, |lint| {
41 lint.build("item is named 'lintmetoo'").set_span(it.span).emit()
48 pub fn plugin_registrar(reg: &mut Registry) {
49 reg.lint_store.register_lints(&[&TEST_RUSTC_TOOL_LINT, &TEST_LINT, &TEST_GROUP]);
50 reg.lint_store.register_early_pass(|| box Pass);
51 reg.lint_store.register_group(
55 vec![LintId::of(&TEST_LINT), LintId::of(&TEST_GROUP)],