]> git.lizzy.rs Git - rust.git/blob - src/test/ui-fulldeps/auxiliary/lint-for-crate.rs
Rollup merge of #67887 - anp:tracked-std-panics, r=nagisa
[rust.git] / src / test / ui-fulldeps / auxiliary / lint-for-crate.rs
1 // force-host
2
3 #![feature(plugin_registrar, rustc_private)]
4 #![feature(box_syntax)]
5
6 #[macro_use] extern crate rustc;
7 #[macro_use] extern crate rustc_session;
8 extern crate rustc_driver;
9 extern crate rustc_hir;
10 extern crate rustc_span;
11 extern crate syntax;
12
13 use rustc::lint::{LateContext, LintContext, LintPass, LateLintPass, LintArray};
14 use rustc_driver::plugin::Registry;
15 use rustc_span::symbol::Symbol;
16 use syntax::attr;
17
18 declare_lint! {
19     CRATE_NOT_OKAY,
20     Warn,
21     "crate not marked with #![crate_okay]"
22 }
23
24 declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
25
26 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
27     fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
28         if !attr::contains_name(&krate.attrs, Symbol::intern("crate_okay")) {
29             cx.span_lint(CRATE_NOT_OKAY, krate.span,
30                          "crate is not marked with #![crate_okay]");
31         }
32     }
33 }
34
35 #[plugin_registrar]
36 pub fn plugin_registrar(reg: &mut Registry) {
37     reg.lint_store.register_lints(&[&CRATE_NOT_OKAY]);
38     reg.lint_store.register_late_pass(|| box Pass);
39 }