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