]>
Commit | Line | Data |
---|---|---|
c34b1796 AL |
1 | // force-host |
2 | ||
3 | #![feature(plugin_registrar, rustc_private)] | |
4 | #![feature(box_syntax)] | |
5 | ||
c34b1796 | 6 | #[macro_use] extern crate rustc; |
416331ca | 7 | extern crate rustc_driver; |
b039eaaf | 8 | extern crate syntax; |
c34b1796 | 9 | |
e74abb32 | 10 | use rustc::lint::{LateContext, LintContext, LintPass, LateLintPass}; |
e1599b0c | 11 | use rustc_driver::plugin::Registry; |
54a0048b | 12 | use rustc::hir; |
b039eaaf | 13 | use syntax::attr; |
48663c56 | 14 | use syntax::symbol::Symbol; |
c34b1796 | 15 | |
2c00a5a8 | 16 | macro_rules! fake_lint_pass { |
e74abb32 | 17 | ($struct:ident, $($attr:expr),*) => { |
2c00a5a8 XL |
18 | struct $struct; |
19 | ||
20 | impl LintPass for $struct { | |
9fa01778 XL |
21 | fn name(&self) -> &'static str { |
22 | stringify!($struct) | |
23 | } | |
2c00a5a8 | 24 | } |
c34b1796 | 25 | |
2c00a5a8 XL |
26 | impl<'a, 'tcx> LateLintPass<'a, 'tcx> for $struct { |
27 | fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) { | |
28 | $( | |
29 | if !attr::contains_name(&krate.attrs, $attr) { | |
30 | cx.span_lint(CRATE_NOT_OKAY, krate.span, | |
31 | &format!("crate is not marked with #![{}]", $attr)); | |
32 | } | |
33 | )* | |
34 | } | |
35 | } | |
c34b1796 | 36 | |
c34b1796 | 37 | } |
b039eaaf | 38 | } |
c34b1796 | 39 | |
2c00a5a8 XL |
40 | declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]"); |
41 | declare_lint!(CRATE_NOT_RED, Warn, "crate not marked with #![crate_red]"); | |
42 | declare_lint!(CRATE_NOT_BLUE, Warn, "crate not marked with #![crate_blue]"); | |
43 | declare_lint!(CRATE_NOT_GREY, Warn, "crate not marked with #![crate_grey]"); | |
44 | declare_lint!(CRATE_NOT_GREEN, Warn, "crate not marked with #![crate_green]"); | |
45 | ||
46 | fake_lint_pass! { | |
47 | PassOkay, | |
48663c56 | 48 | Symbol::intern("rustc_crate_okay") |
2c00a5a8 XL |
49 | } |
50 | ||
51 | fake_lint_pass! { | |
52 | PassRedBlue, | |
48663c56 | 53 | Symbol::intern("rustc_crate_red"), Symbol::intern("rustc_crate_blue") |
2c00a5a8 XL |
54 | } |
55 | ||
56 | fake_lint_pass! { | |
57 | PassGreyGreen, | |
48663c56 | 58 | Symbol::intern("rustc_crate_grey"), Symbol::intern("rustc_crate_green") |
c34b1796 AL |
59 | } |
60 | ||
61 | #[plugin_registrar] | |
62 | pub fn plugin_registrar(reg: &mut Registry) { | |
e74abb32 XL |
63 | reg.lint_store.register_lints(&[ |
64 | &CRATE_NOT_OKAY, | |
65 | &CRATE_NOT_RED, | |
66 | &CRATE_NOT_BLUE, | |
67 | &CRATE_NOT_GREY, | |
68 | &CRATE_NOT_GREEN, | |
69 | ]); | |
70 | reg.lint_store.register_late_pass(|| box PassOkay); | |
71 | reg.lint_store.register_late_pass(|| box PassRedBlue); | |
72 | reg.lint_store.register_late_pass(|| box PassGreyGreen); | |
c34b1796 | 73 | } |