rust/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs

38 lines
1.2 KiB
Rust
Raw Normal View History

// force-host
#![feature(plugin_registrar)]
#![feature(box_syntax, rustc_private)]
// Load rustc as a plugin to get macros.
2019-07-06 12:56:20 -05:00
extern crate rustc_driver;
2020-01-04 22:35:51 -06:00
extern crate rustc_hir;
2020-01-09 23:53:07 -06:00
#[macro_use] extern crate rustc_lint;
#[macro_use] extern crate rustc_session;
2020-01-09 23:53:07 -06:00
use rustc_lint::{LateContext, LintContext, LintPass, LateLintPass, LintArray, LintId};
use rustc_driver::plugin::Registry;
declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
declare_lint!(PLEASE_LINT, Warn, "Warn about items named 'pleaselintme'");
declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
2020-01-04 22:35:51 -06:00
fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
match &*it.ident.as_str() {
"lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"),
"pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"),
_ => {}
}
}
}
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
2019-10-09 14:41:17 -05:00
reg.lint_store.register_lints(&[&TEST_LINT, &PLEASE_LINT]);
reg.lint_store.register_late_pass(|| box Pass);
reg.lint_store.register_group(true, "lint_me", None,
vec![LintId::of(&TEST_LINT), LintId::of(&PLEASE_LINT)]);
}