]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // force-host |
2 | ||
3 | #![feature(plugin_registrar)] | |
c34b1796 | 4 | #![feature(box_syntax, rustc_private)] |
1a4d82fc | 5 | |
0731742a | 6 | // Load rustc as a plugin to get macros. |
416331ca | 7 | extern crate rustc_driver; |
dfeec247 | 8 | extern crate rustc_hir; |
74b04a01 XL |
9 | #[macro_use] |
10 | extern crate rustc_lint; | |
11 | #[macro_use] | |
12 | extern crate rustc_session; | |
1a4d82fc | 13 | |
e1599b0c | 14 | use rustc_driver::plugin::Registry; |
74b04a01 | 15 | use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintId, LintPass}; |
1a4d82fc JJ |
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 | ||
532ac7d7 | 21 | declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]); |
1a4d82fc | 22 | |
476ff2be | 23 | impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { |
dfeec247 | 24 | fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) { |
0731742a | 25 | match &*it.ident.as_str() { |
74b04a01 XL |
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 | }), | |
c1a9b12d | 32 | _ => {} |
1a4d82fc JJ |
33 | } |
34 | } | |
35 | } | |
36 | ||
37 | #[plugin_registrar] | |
38 | pub fn plugin_registrar(reg: &mut Registry) { | |
e74abb32 XL |
39 | reg.lint_store.register_lints(&[&TEST_LINT, &PLEASE_LINT]); |
40 | reg.lint_store.register_late_pass(|| box Pass); | |
74b04a01 XL |
41 | reg.lint_store.register_group( |
42 | true, | |
43 | "lint_me", | |
44 | None, | |
45 | vec![LintId::of(&TEST_LINT), LintId::of(&PLEASE_LINT)], | |
46 | ); | |
1a4d82fc | 47 | } |