2016-04-26 12:51:14 -05:00
|
|
|
// force-host
|
|
|
|
|
2021-05-14 08:37:53 -05:00
|
|
|
#![feature(rustc_private)]
|
2016-04-26 12:51:14 -05:00
|
|
|
|
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
|
|
|
extern crate rustc_lint;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_session;
|
2020-02-29 11:37:32 -06:00
|
|
|
extern crate rustc_ast;
|
2021-09-12 06:19:04 -05:00
|
|
|
extern crate rustc_span;
|
2016-04-26 12:51:14 -05:00
|
|
|
|
2023-03-19 12:32:34 -05:00
|
|
|
use rustc_ast::attr;
|
2019-07-16 12:08:32 -05:00
|
|
|
use rustc_driver::plugin::Registry;
|
2021-09-12 06:19:04 -05:00
|
|
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
|
|
|
use rustc_span::def_id::CRATE_DEF_ID;
|
2020-01-01 17:01:07 -06:00
|
|
|
use rustc_span::symbol::Symbol;
|
2016-04-26 12:51:14 -05:00
|
|
|
|
2019-04-03 09:05:40 -05:00
|
|
|
declare_lint! {
|
|
|
|
CRATE_NOT_OKAY,
|
|
|
|
Warn,
|
|
|
|
"crate not marked with #![crate_okay]"
|
2016-04-26 12:51:14 -05:00
|
|
|
}
|
|
|
|
|
2019-04-03 09:05:40 -05:00
|
|
|
declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
|
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
impl<'tcx> LateLintPass<'tcx> for Pass {
|
2021-09-12 06:19:04 -05:00
|
|
|
fn check_crate(&mut self, cx: &LateContext) {
|
2020-12-05 14:23:37 -06:00
|
|
|
let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
|
2021-09-12 06:19:04 -05:00
|
|
|
let span = cx.tcx.def_span(CRATE_DEF_ID);
|
2023-03-19 12:32:34 -05:00
|
|
|
if !attr::contains_name(attrs, Symbol::intern("crate_okay")) {
|
|
|
|
cx.lint(CRATE_NOT_OKAY, "crate is not marked with #![crate_okay]", |lint| {
|
|
|
|
lint.set_span(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(&[&CRATE_NOT_OKAY]);
|
2022-09-06 13:23:03 -05:00
|
|
|
reg.lint_store.register_late_pass(|_| Box::new(Pass));
|
2016-04-26 12:51:14 -05:00
|
|
|
}
|