2016-04-26 12:51:14 -05:00
|
|
|
// force-host
|
|
|
|
|
|
|
|
#![feature(plugin_registrar)]
|
|
|
|
#![feature(box_syntax, rustc_private)]
|
|
|
|
|
2018-11-30 20:47:08 -06:00
|
|
|
// Load rustc as a plugin to get macros.
|
2019-12-01 12:11:31 -06:00
|
|
|
#[macro_use] extern crate rustc;
|
|
|
|
#[macro_use] extern crate rustc_session;
|
2019-07-06 12:56:20 -05:00
|
|
|
extern crate rustc_driver;
|
2016-04-26 12:51:14 -05:00
|
|
|
|
|
|
|
use rustc::hir;
|
2019-10-09 14:41:17 -05:00
|
|
|
use rustc::lint::{LateContext, LintContext, LintPass, LateLintPass, LintArray, LintId};
|
2019-07-16 12:08:32 -05:00
|
|
|
use rustc_driver::plugin::Registry;
|
2016-04-26 12:51:14 -05:00
|
|
|
|
|
|
|
declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
|
|
|
|
|
|
|
|
declare_lint!(PLEASE_LINT, Warn, "Warn about items named 'pleaselintme'");
|
|
|
|
|
2019-04-03 09:05:40 -05:00
|
|
|
declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
|
2016-04-26 12:51:14 -05:00
|
|
|
|
2016-12-07 06:14:47 -06:00
|
|
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
2016-12-07 06:56:36 -06:00
|
|
|
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
2018-11-30 20:47:08 -06:00
|
|
|
match &*it.ident.as_str() {
|
2016-04-26 12:51:14 -05:00
|
|
|
"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)]);
|
2016-04-26 12:51:14 -05:00
|
|
|
}
|