3 #![feature(rustc_private)]
5 // Load rustc as a plugin to get macros.
6 extern crate rustc_driver;
7 extern crate rustc_hir;
9 extern crate rustc_lint;
11 extern crate rustc_session;
13 use rustc_driver::plugin::Registry;
14 use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintId, LintPass};
16 declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
18 declare_lint!(PLEASE_LINT, Warn, "Warn about items named 'pleaselintme'");
20 declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
22 impl<'tcx> LateLintPass<'tcx> for Pass {
23 fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
24 match it.ident.as_str() {
25 "lintme" => cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span)),
27 cx.lint(PLEASE_LINT, "item is named 'pleaselintme'", |lint| lint.set_span(it.span))
35 fn __rustc_plugin_registrar(reg: &mut Registry) {
36 reg.lint_store.register_lints(&[&TEST_LINT, &PLEASE_LINT]);
37 reg.lint_store.register_late_pass(|_| Box::new(Pass));
38 reg.lint_store.register_group(
42 vec![LintId::of(&TEST_LINT), LintId::of(&PLEASE_LINT)],