]> git.lizzy.rs Git - rust.git/blob - src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs
Rollup merge of #99156 - lcnr:omoe-wa, r=wesleywiser
[rust.git] / src / test / 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, |lint| {
26                 lint.build("item is named 'lintme'").set_span(it.span).emit();
27             }),
28             "pleaselintme" => cx.lint(PLEASE_LINT, |lint| {
29                 lint.build("item is named 'pleaselintme'").set_span(it.span).emit();
30             }),
31             _ => {}
32         }
33     }
34 }
35
36 #[no_mangle]
37 fn __rustc_plugin_registrar(reg: &mut Registry) {
38     reg.lint_store.register_lints(&[&TEST_LINT, &PLEASE_LINT]);
39     reg.lint_store.register_late_pass(|| Box::new(Pass));
40     reg.lint_store.register_group(
41         true,
42         "lint_me",
43         None,
44         vec![LintId::of(&TEST_LINT), LintId::of(&PLEASE_LINT)],
45     );
46 }