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.
|
2016-04-26 12:51:14 -05:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc;
|
2019-07-06 12:56:20 -05:00
|
|
|
extern crate rustc_driver;
|
2016-04-26 12:51:14 -05:00
|
|
|
|
|
|
|
use rustc::hir;
|
|
|
|
use rustc::lint::{LateContext, LintContext, LintPass, LateLintPass, LateLintPassObject, LintArray};
|
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) {
|
2016-12-07 06:14:47 -06:00
|
|
|
reg.register_late_lint_pass(box Pass);
|
2018-08-27 16:24:42 -05:00
|
|
|
reg.register_lint_group("lint_me", None, vec![TEST_LINT, PLEASE_LINT]);
|
2016-04-26 12:51:14 -05:00
|
|
|
}
|