]> git.lizzy.rs Git - rust.git/blob - src/test/ui-fulldeps/auxiliary/lint-tool-test.rs
fix ui-fulldeps & tests fallout
[rust.git] / src / test / ui-fulldeps / auxiliary / lint-tool-test.rs
1 #![feature(plugin_registrar)]
2 #![feature(box_syntax, rustc_private)]
3
4 extern crate syntax;
5
6 // Load rustc as a plugin to get macros
7 extern crate rustc_driver;
8 #[macro_use] extern crate rustc_lint;
9 #[macro_use] extern crate rustc_session;
10
11 use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass, LintId};
12 use rustc_driver::plugin::Registry;
13 use syntax::ast;
14 declare_tool_lint!(pub clippy::TEST_LINT, Warn, "Warn about stuff");
15 declare_tool_lint!(
16     /// Some docs
17     pub clippy::TEST_GROUP,
18     Warn, "Warn about other stuff"
19 );
20
21 declare_tool_lint!(
22     /// Some docs
23     pub rustc::TEST_RUSTC_TOOL_LINT,
24     Deny,
25     "Deny internal stuff"
26 );
27
28 declare_lint_pass!(Pass => [TEST_LINT, TEST_GROUP, TEST_RUSTC_TOOL_LINT]);
29
30 impl EarlyLintPass for Pass {
31     fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
32         if it.ident.name.as_str() == "lintme" {
33             cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
34         }
35         if it.ident.name.as_str() == "lintmetoo" {
36             cx.span_lint(TEST_GROUP, it.span, "item is named 'lintmetoo'");
37         }
38     }
39 }
40
41 #[plugin_registrar]
42 pub fn plugin_registrar(reg: &mut Registry) {
43     reg.lint_store.register_lints(&[&TEST_RUSTC_TOOL_LINT, &TEST_LINT, &TEST_GROUP]);
44     reg.lint_store.register_early_pass(|| box Pass);
45     reg.lint_store.register_group(true, "clippy::group", Some("clippy_group"),
46         vec![LintId::of(&TEST_LINT), LintId::of(&TEST_GROUP)]);
47 }