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
|
|
|
|
2020-02-29 11:37:32 -06:00
|
|
|
extern crate rustc_ast;
|
2016-04-26 12:51:14 -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
|
|
|
extern crate rustc_lint;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_session;
|
2016-04-26 12:51:14 -05:00
|
|
|
|
2023-09-28 09:00:38 -05:00
|
|
|
use rustc_ast::ast;
|
2019-07-16 12:08:32 -05:00
|
|
|
use rustc_driver::plugin::Registry;
|
2023-09-28 09:00:38 -05:00
|
|
|
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
|
|
|
|
|
2016-04-26 12:51:14 -05:00
|
|
|
declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
|
|
|
|
|
2019-04-03 09:05:40 -05:00
|
|
|
declare_lint_pass!(Pass => [TEST_LINT]);
|
2016-04-26 12:51:14 -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" {
|
2022-09-22 09:25:05 -05:00
|
|
|
cx.lint(TEST_LINT, "item is named 'lintme'", |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]);
|
2021-08-24 19:39:40 -05:00
|
|
|
reg.lint_store.register_early_pass(|| Box::new(Pass));
|
2016-04-26 12:51:14 -05:00
|
|
|
}
|