3 #![feature(rustc_private)]
5 extern crate rustc_driver;
6 extern crate rustc_hir;
7 extern crate rustc_lint;
8 extern crate rustc_span;
10 extern crate rustc_session;
11 extern crate rustc_ast;
14 use rustc_driver::plugin::Registry;
15 use rustc_lint::{LateContext, LateLintPass, LintContext, LintPass};
16 use rustc_span::def_id::CRATE_DEF_ID;
17 use rustc_span::symbol::Symbol;
19 macro_rules! fake_lint_pass {
20 ($struct:ident, $($attr:expr),*) => {
23 impl LintPass for $struct {
24 fn name(&self) -> &'static str {
29 impl LateLintPass<'_> for $struct {
30 fn check_crate(&mut self, cx: &LateContext) {
31 let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
32 let span = cx.tcx.def_span(CRATE_DEF_ID);
34 if !cx.sess().contains_name(attrs, $attr) {
35 cx.lint(CRATE_NOT_OKAY, |lint| {
36 let msg = format!("crate is not marked with #![{}]", $attr);
37 lint.build(&msg).set_span(span).emit();
47 declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
48 declare_lint!(CRATE_NOT_RED, Warn, "crate not marked with #![crate_red]");
49 declare_lint!(CRATE_NOT_BLUE, Warn, "crate not marked with #![crate_blue]");
50 declare_lint!(CRATE_NOT_GREY, Warn, "crate not marked with #![crate_grey]");
51 declare_lint!(CRATE_NOT_GREEN, Warn, "crate not marked with #![crate_green]");
55 Symbol::intern("crate_okay")
60 Symbol::intern("crate_red"), Symbol::intern("crate_blue")
65 Symbol::intern("crate_grey"), Symbol::intern("crate_green")
69 fn __rustc_plugin_registrar(reg: &mut Registry) {
70 reg.lint_store.register_lints(&[
77 reg.lint_store.register_late_pass(|| Box::new(PassOkay));
78 reg.lint_store.register_late_pass(|| Box::new(PassRedBlue));
79 reg.lint_store.register_late_pass(|| Box::new(PassGreyGreen));