]> git.proxmox.com Git - rustc.git/blame - src/test/ui-fulldeps/auxiliary/lint-for-crate-rpass.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / test / ui-fulldeps / auxiliary / lint-for-crate-rpass.rs
CommitLineData
c34b1796
AL
1// force-host
2
3#![feature(plugin_registrar, rustc_private)]
4#![feature(box_syntax)]
c34b1796 5#[macro_use] extern crate rustc;
60c5eb7d 6#[macro_use] extern crate rustc_session;
416331ca 7extern crate rustc_driver;
b039eaaf 8extern crate syntax;
c34b1796 9
e74abb32 10use rustc::lint::{LateContext, LintContext, LintPass, LateLintPass};
e1599b0c 11use rustc_driver::plugin::Registry;
54a0048b 12use rustc::hir;
b039eaaf 13use syntax::attr;
48663c56 14use syntax::symbol::Symbol;
c34b1796 15
2c00a5a8 16macro_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
40declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
41declare_lint!(CRATE_NOT_RED, Warn, "crate not marked with #![crate_red]");
42declare_lint!(CRATE_NOT_BLUE, Warn, "crate not marked with #![crate_blue]");
43declare_lint!(CRATE_NOT_GREY, Warn, "crate not marked with #![crate_grey]");
44declare_lint!(CRATE_NOT_GREEN, Warn, "crate not marked with #![crate_green]");
45
46fake_lint_pass! {
47 PassOkay,
48663c56 48 Symbol::intern("rustc_crate_okay")
2c00a5a8
XL
49}
50
51fake_lint_pass! {
52 PassRedBlue,
48663c56 53 Symbol::intern("rustc_crate_red"), Symbol::intern("rustc_crate_blue")
2c00a5a8
XL
54}
55
56fake_lint_pass! {
57 PassGreyGreen,
48663c56 58 Symbol::intern("rustc_crate_grey"), Symbol::intern("rustc_crate_green")
c34b1796
AL
59}
60
61#[plugin_registrar]
62pub 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}