2018-07-30 04:30:07 -05:00
|
|
|
#![feature(plugin_registrar)]
|
|
|
|
#![feature(box_syntax, rustc_private)]
|
|
|
|
|
2020-02-29 11:37:32 -06:00
|
|
|
extern crate rustc_ast;
|
2018-07-30 04:30:07 -05:00
|
|
|
|
|
|
|
// Load rustc as a plugin to get macros
|
2019-07-06 12:56:20 -05:00
|
|
|
extern crate rustc_driver;
|
2020-02-06 04:22:25 -06:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_lint;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_session;
|
2018-07-30 04:30:07 -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::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintId, LintPass};
|
2020-04-27 12:56:11 -05:00
|
|
|
use rustc_ast as ast;
|
2018-07-30 04:30:07 -05:00
|
|
|
declare_tool_lint!(pub clippy::TEST_LINT, Warn, "Warn about stuff");
|
2019-02-27 09:56:58 -06:00
|
|
|
declare_tool_lint!(
|
|
|
|
/// Some docs
|
|
|
|
pub clippy::TEST_GROUP,
|
|
|
|
Warn, "Warn about other stuff"
|
|
|
|
);
|
2018-07-30 04:30:07 -05:00
|
|
|
|
2019-06-24 03:43:51 -05:00
|
|
|
declare_tool_lint!(
|
|
|
|
/// Some docs
|
|
|
|
pub rustc::TEST_RUSTC_TOOL_LINT,
|
|
|
|
Deny,
|
|
|
|
"Deny internal stuff"
|
|
|
|
);
|
|
|
|
|
|
|
|
declare_lint_pass!(Pass => [TEST_LINT, TEST_GROUP, TEST_RUSTC_TOOL_LINT]);
|
2018-07-30 04:30:07 -05:00
|
|
|
|
|
|
|
impl EarlyLintPass for Pass {
|
|
|
|
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
|
2019-05-07 01:03:44 -05:00
|
|
|
if it.ident.name.as_str() == "lintme" {
|
2020-02-06 04:22:25 -06:00
|
|
|
cx.lint(TEST_LINT, |lint| {
|
|
|
|
lint.build("item is named 'lintme'").set_span(it.span).emit()
|
|
|
|
});
|
2018-07-30 04:30:07 -05:00
|
|
|
}
|
2019-05-07 01:03:44 -05:00
|
|
|
if it.ident.name.as_str() == "lintmetoo" {
|
2020-02-06 04:22:25 -06:00
|
|
|
cx.lint(TEST_GROUP, |lint| {
|
|
|
|
lint.build("item is named 'lintmetoo'").set_span(it.span).emit()
|
|
|
|
});
|
2018-08-27 16:22:47 -05:00
|
|
|
}
|
2018-07-30 04:30:07 -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_RUSTC_TOOL_LINT, &TEST_LINT, &TEST_GROUP]);
|
|
|
|
reg.lint_store.register_early_pass(|| box Pass);
|
2020-02-06 04:22:25 -06:00
|
|
|
reg.lint_store.register_group(
|
|
|
|
true,
|
|
|
|
"clippy::group",
|
|
|
|
Some("clippy_group"),
|
|
|
|
vec![LintId::of(&TEST_LINT), LintId::of(&TEST_GROUP)],
|
|
|
|
);
|
2018-07-30 04:30:07 -05:00
|
|
|
}
|