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