]> git.lizzy.rs Git - rust.git/blob - src/test/ui-fulldeps/auxiliary/lint-for-crate-rpass.rs
fix ui-fulldeps & tests fallout
[rust.git] / src / test / ui-fulldeps / auxiliary / lint-for-crate-rpass.rs
1 // force-host
2
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;
10 extern crate syntax;
11
12 use rustc_lint::{LateContext, LintContext, LintPass, LateLintPass};
13 use rustc_driver::plugin::Registry;
14 use rustc_span::symbol::Symbol;
15 use syntax::attr;
16
17 macro_rules! fake_lint_pass {
18     ($struct:ident, $($attr:expr),*) => {
19         struct $struct;
20
21         impl LintPass for $struct {
22             fn name(&self) -> &'static str {
23                 stringify!($struct)
24             }
25         }
26
27         impl<'a, 'tcx> LateLintPass<'a, 'tcx> for $struct {
28             fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
29                 $(
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));
33                     }
34                 )*
35             }
36         }
37
38     }
39 }
40
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]");
46
47 fake_lint_pass! {
48     PassOkay,
49     Symbol::intern("rustc_crate_okay")
50 }
51
52 fake_lint_pass! {
53     PassRedBlue,
54     Symbol::intern("rustc_crate_red"), Symbol::intern("rustc_crate_blue")
55 }
56
57 fake_lint_pass! {
58     PassGreyGreen,
59     Symbol::intern("rustc_crate_grey"), Symbol::intern("rustc_crate_green")
60 }
61
62 #[plugin_registrar]
63 pub fn plugin_registrar(reg: &mut Registry) {
64     reg.lint_store.register_lints(&[
65         &CRATE_NOT_OKAY,
66         &CRATE_NOT_RED,
67         &CRATE_NOT_BLUE,
68         &CRATE_NOT_GREY,
69         &CRATE_NOT_GREEN,
70     ]);
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);
74 }