2016-04-26 12:51:14 -05:00
|
|
|
// force-host
|
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
#![feature(rustc_private)]
|
2016-04-26 12:51:14 -05:00
|
|
|
|
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
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
impl<'tcx> LateLintPass<'tcx> for Pass {
|
2020-01-04 22:35:51 -06:00
|
|
|
fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
|
2021-12-14 23:13:11 -06:00
|
|
|
match it.ident.as_str() {
|
2022-09-22 09:25:05 -05:00
|
|
|
"lintme" => cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span)),
|
|
|
|
"pleaselintme" => {
|
|
|
|
cx.lint(PLEASE_LINT, "item is named 'pleaselintme'", |lint| lint.set_span(it.span))
|
|
|
|
}
|
2016-04-26 12:51:14 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-14 08:37:53 -05:00
|
|
|
#[no_mangle]
|
|
|
|
fn __rustc_plugin_registrar(reg: &mut Registry) {
|
2019-10-09 14:41:17 -05:00
|
|
|
reg.lint_store.register_lints(&[&TEST_LINT, &PLEASE_LINT]);
|
2022-09-06 13:23:03 -05:00
|
|
|
reg.lint_store.register_late_pass(|_| Box::new(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
|
|
|
}
|