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-07-06 12:56:20 -05:00
|
|
|
extern crate rustc_driver;
|
2020-01-04 22:35:51 -06:00
|
|
|
extern crate rustc_hir;
|
2020-02-06 04:22:25 -06:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_lint;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_session;
|
2016-04-26 12:51:14 -05:00
|
|
|
|
2019-07-16 12:08:32 -05:00
|
|
|
use rustc_driver::plugin::Registry;
|
2020-02-06 04:22:25 -06:00
|
|
|
use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintId, LintPass};
|
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 {
|
2020-01-04 22:35:51 -06:00
|
|
|
fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
|
2018-11-30 20:47:08 -06:00
|
|
|
match &*it.ident.as_str() {
|
2020-02-06 04:22:25 -06:00
|
|
|
"lintme" => cx.lint(TEST_LINT, |lint| {
|
|
|
|
lint.build("item is named 'lintme'").set_span(it.span).emit()
|
|
|
|
}),
|
|
|
|
"pleaselintme" => cx.lint(PLEASE_LINT, |lint| {
|
|
|
|
lint.build("item is named 'pleaselintme'").set_span(it.span).emit()
|
|
|
|
}),
|
2016-04-26 12:51:14 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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);
|
2020-02-06 04:22:25 -06:00
|
|
|
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
|
|
|
}
|