]> git.lizzy.rs Git - rust.git/blob - src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs
Rollup merge of #99156 - lcnr:omoe-wa, r=wesleywiser
[rust.git] / src / test / ui-fulldeps / auxiliary / lint-plugin-test.rs
1 // force-host
2
3 #![feature(rustc_private)]
4
5 extern crate rustc_ast;
6
7 // Load rustc as a plugin to get macros
8 extern crate rustc_driver;
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::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
16 use rustc_ast as ast;
17 declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
18
19 declare_lint_pass!(Pass => [TEST_LINT]);
20
21 impl EarlyLintPass for Pass {
22     fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
23         if it.ident.name.as_str() == "lintme" {
24             cx.lint(TEST_LINT, |lint| {
25                 lint.build("item is named 'lintme'").set_span(it.span).emit();
26             });
27         }
28     }
29 }
30
31 #[no_mangle]
32 fn __rustc_plugin_registrar(reg: &mut Registry) {
33     reg.lint_store.register_lints(&[&TEST_LINT]);
34     reg.lint_store.register_early_pass(|| Box::new(Pass));
35 }