]> git.proxmox.com Git - rustc.git/blob - src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs
New upstream version 1.41.1+dfsg1
[rustc.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 #[macro_use] extern crate rustc;
8 #[macro_use] extern crate rustc_session;
9 extern crate rustc_driver;
10
11 use rustc::hir;
12 use rustc::lint::{LateContext, LintContext, LintPass, LateLintPass, LintArray, LintId};
13 use rustc_driver::plugin::Registry;
14
15 declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
16
17 declare_lint!(PLEASE_LINT, Warn, "Warn about items named 'pleaselintme'");
18
19 declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
20
21 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
22 fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
23 match &*it.ident.as_str() {
24 "lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"),
25 "pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"),
26 _ => {}
27 }
28 }
29 }
30
31 #[plugin_registrar]
32 pub fn plugin_registrar(reg: &mut Registry) {
33 reg.lint_store.register_lints(&[&TEST_LINT, &PLEASE_LINT]);
34 reg.lint_store.register_late_pass(|| box Pass);
35 reg.lint_store.register_group(true, "lint_me", None,
36 vec![LintId::of(&TEST_LINT), LintId::of(&PLEASE_LINT)]);
37 }