]> git.lizzy.rs Git - rust.git/blob - src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs
Rollup merge of #80193 - zseri:stabilize-osstring-ascii, r=m-ou-se
[rust.git] / src / test / ui-fulldeps / auxiliary / lint-plugin-test.rs
1 // force-host
2
3 #![feature(plugin_registrar)]
4 #![feature(box_syntax, rustc_private)]
5
6 extern crate rustc_ast;
7
8 // Load rustc as a plugin to get macros
9 extern crate rustc_driver;
10 #[macro_use]
11 extern crate rustc_lint;
12 #[macro_use]
13 extern crate rustc_session;
14
15 use rustc_driver::plugin::Registry;
16 use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
17 use rustc_ast as ast;
18 declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
19
20 declare_lint_pass!(Pass => [TEST_LINT]);
21
22 impl EarlyLintPass for Pass {
23     fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
24         if it.ident.name.as_str() == "lintme" {
25             cx.lint(TEST_LINT, |lint| {
26                 lint.build("item is named 'lintme'").set_span(it.span).emit()
27             });
28         }
29     }
30 }
31
32 #[plugin_registrar]
33 pub fn plugin_registrar(reg: &mut Registry) {
34     reg.lint_store.register_lints(&[&TEST_LINT]);
35     reg.lint_store.register_early_pass(|| box Pass);
36 }