]> git.lizzy.rs Git - rust.git/blob - tests/ui-fulldeps/auxiliary/lint-group-plugin-test.rs
make more readable
[rust.git] / tests / ui-fulldeps / auxiliary / lint-group-plugin-test.rs
1 // force-host
2
3 #![feature(rustc_private)]
4
5 // Load rustc as a plugin to get macros.
6 extern crate rustc_driver;
7 extern crate rustc_hir;
8 #[macro_use]
9 extern crate rustc_lint;
10 #[macro_use]
11 extern crate rustc_session;
12
13 use rustc_driver::plugin::Registry;
14 use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintId, LintPass};
15
16 declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
17
18 declare_lint!(PLEASE_LINT, Warn, "Warn about items named 'pleaselintme'");
19
20 declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
21
22 impl<'tcx> LateLintPass<'tcx> for Pass {
23     fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
24         match it.ident.as_str() {
25             "lintme" => cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span)),
26             "pleaselintme" => {
27                 cx.lint(PLEASE_LINT, "item is named 'pleaselintme'", |lint| lint.set_span(it.span))
28             }
29             _ => {}
30         }
31     }
32 }
33
34 #[no_mangle]
35 fn __rustc_plugin_registrar(reg: &mut Registry) {
36     reg.lint_store.register_lints(&[&TEST_LINT, &PLEASE_LINT]);
37     reg.lint_store.register_late_pass(|_| Box::new(Pass));
38     reg.lint_store.register_group(
39         true,
40         "lint_me",
41         None,
42         vec![LintId::of(&TEST_LINT), LintId::of(&PLEASE_LINT)],
43     );
44 }