]> git.lizzy.rs Git - rust.git/blob - src/test/ui-fulldeps/auxiliary/lint-for-crate.rs
Auto merge of #75137 - Aaron1011:fix/hygiene-skip-expndata, r=petrochenkov
[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 extern crate rustc_driver;
7 extern crate rustc_hir;
8 #[macro_use]
9 extern crate rustc_lint;
10 #[macro_use]
11 extern crate rustc_session;
12 extern crate rustc_span;
13 extern crate rustc_ast;
14
15 use rustc_driver::plugin::Registry;
16 use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
17 use rustc_span::symbol::Symbol;
18 use rustc_ast::attr;
19
20 declare_lint! {
21     CRATE_NOT_OKAY,
22     Warn,
23     "crate not marked with #![crate_okay]"
24 }
25
26 declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
27
28 impl<'tcx> LateLintPass<'tcx> for Pass {
29     fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
30         if !cx.sess().contains_name(&krate.item.attrs, Symbol::intern("crate_okay")) {
31             cx.lint(CRATE_NOT_OKAY, |lint| {
32                 lint.build("crate is not marked with #![crate_okay]")
33                     .set_span(krate.item.span)
34                     .emit()
35             });
36         }
37     }
38 }
39
40 #[plugin_registrar]
41 pub fn plugin_registrar(reg: &mut Registry) {
42     reg.lint_store.register_lints(&[&CRATE_NOT_OKAY]);
43     reg.lint_store.register_late_pass(|| box Pass);
44 }