3 #![feature(plugin_registrar, rustc_private)]
4 #![feature(box_syntax)]
6 extern crate rustc_driver;
7 extern crate rustc_hir;
8 extern crate rustc_lint;
9 extern crate rustc_span;
11 extern crate rustc_session;
12 extern crate rustc_ast;
15 use rustc_driver::plugin::Registry;
16 use rustc_lint::{LateContext, LateLintPass, LintContext, LintPass};
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, krate: &rustc_hir::Crate) {
31 let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
33 if !cx.sess().contains_name(attrs, $attr) {
34 cx.lint(CRATE_NOT_OKAY, |lint| {
35 let msg = format!("crate is not marked with #![{}]", $attr);
36 lint.build(&msg).set_span(krate.item.inner).emit()
46 declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
47 declare_lint!(CRATE_NOT_RED, Warn, "crate not marked with #![crate_red]");
48 declare_lint!(CRATE_NOT_BLUE, Warn, "crate not marked with #![crate_blue]");
49 declare_lint!(CRATE_NOT_GREY, Warn, "crate not marked with #![crate_grey]");
50 declare_lint!(CRATE_NOT_GREEN, Warn, "crate not marked with #![crate_green]");
54 Symbol::intern("crate_okay")
59 Symbol::intern("crate_red"), Symbol::intern("crate_blue")
64 Symbol::intern("crate_grey"), Symbol::intern("crate_green")
68 pub fn plugin_registrar(reg: &mut Registry) {
69 reg.lint_store.register_lints(&[
76 reg.lint_store.register_late_pass(|| box PassOkay);
77 reg.lint_store.register_late_pass(|| box PassRedBlue);
78 reg.lint_store.register_late_pass(|| box PassGreyGreen);