3 #![feature(plugin_registrar, rustc_private)]
4 #![feature(box_syntax)]
5 extern crate rustc_driver;
6 extern crate rustc_hir;
7 extern crate rustc_span;
8 #[macro_use] extern crate rustc_lint;
9 #[macro_use] extern crate rustc_session;
12 use rustc_lint::{LateContext, LintContext, LintPass, LateLintPass};
13 use rustc_driver::plugin::Registry;
14 use rustc_span::symbol::Symbol;
17 macro_rules! fake_lint_pass {
18 ($struct:ident, $($attr:expr),*) => {
21 impl LintPass for $struct {
22 fn name(&self) -> &'static str {
27 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for $struct {
28 fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
30 if !attr::contains_name(&krate.attrs, $attr) {
31 cx.span_lint(CRATE_NOT_OKAY, krate.span,
32 &format!("crate is not marked with #![{}]", $attr));
41 declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
42 declare_lint!(CRATE_NOT_RED, Warn, "crate not marked with #![crate_red]");
43 declare_lint!(CRATE_NOT_BLUE, Warn, "crate not marked with #![crate_blue]");
44 declare_lint!(CRATE_NOT_GREY, Warn, "crate not marked with #![crate_grey]");
45 declare_lint!(CRATE_NOT_GREEN, Warn, "crate not marked with #![crate_green]");
49 Symbol::intern("rustc_crate_okay")
54 Symbol::intern("rustc_crate_red"), Symbol::intern("rustc_crate_blue")
59 Symbol::intern("rustc_crate_grey"), Symbol::intern("rustc_crate_green")
63 pub fn plugin_registrar(reg: &mut Registry) {
64 reg.lint_store.register_lints(&[
71 reg.lint_store.register_late_pass(|| box PassOkay);
72 reg.lint_store.register_late_pass(|| box PassRedBlue);
73 reg.lint_store.register_late_pass(|| box PassGreyGreen);