2016-04-26 17:51:14 +00:00
|
|
|
// force-host
|
|
|
|
|
2021-08-25 00:39:40 +00:00
|
|
|
#![feature(rustc_private)]
|
2016-04-26 17:51:14 +00:00
|
|
|
|
2020-02-29 17:37:32 +00:00
|
|
|
extern crate rustc_ast;
|
2016-04-26 17:51:14 +00:00
|
|
|
|
|
|
|
// Load rustc as a plugin to get macros
|
2019-07-06 17:56:20 +00:00
|
|
|
extern crate rustc_driver;
|
2020-02-06 10:22:25 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_lint;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_session;
|
2016-04-26 17:51:14 +00:00
|
|
|
|
2019-07-16 17:08:32 +00:00
|
|
|
use rustc_driver::plugin::Registry;
|
2020-02-06 10:22:25 +00:00
|
|
|
use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
|
2020-04-27 17:56:11 +00:00
|
|
|
use rustc_ast as ast;
|
2016-04-26 17:51:14 +00:00
|
|
|
declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
|
|
|
|
|
2019-04-03 14:05:40 +00:00
|
|
|
declare_lint_pass!(Pass => [TEST_LINT]);
|
2016-04-26 17:51:14 +00:00
|
|
|
|
|
|
|
impl EarlyLintPass for Pass {
|
|
|
|
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
|
2019-05-07 06:03:44 +00:00
|
|
|
if it.ident.name.as_str() == "lintme" {
|
2022-09-22 14:25:05 +00:00
|
|
|
cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span));
|
2016-04-26 17:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-14 13:37:53 +00:00
|
|
|
#[no_mangle]
|
|
|
|
fn __rustc_plugin_registrar(reg: &mut Registry) {
|
2019-10-09 19:41:17 +00:00
|
|
|
reg.lint_store.register_lints(&[&TEST_LINT]);
|
2021-08-25 00:39:40 +00:00
|
|
|
reg.lint_store.register_early_pass(|| Box::new(Pass));
|
2016-04-26 17:51:14 +00:00
|
|
|
}
|