]> git.lizzy.rs Git - rust.git/blob - tests/ui-fulldeps/auxiliary/lint-for-crate.rs
Rollup merge of #106670 - albertlarsan68:check-docs-in-pr-ci, r=Mark-Simulacrum
[rust.git] / tests / ui-fulldeps / auxiliary / lint-for-crate.rs
1 // force-host
2
3 #![feature(rustc_private)]
4
5 extern crate rustc_driver;
6 extern crate rustc_hir;
7 #[macro_use]
8 extern crate rustc_lint;
9 #[macro_use]
10 extern crate rustc_session;
11 extern crate rustc_ast;
12 extern crate rustc_span;
13
14 use rustc_driver::plugin::Registry;
15 use rustc_lint::{LateContext, LateLintPass, LintContext};
16 use rustc_span::def_id::CRATE_DEF_ID;
17 use rustc_span::symbol::Symbol;
18
19 declare_lint! {
20     CRATE_NOT_OKAY,
21     Warn,
22     "crate not marked with #![crate_okay]"
23 }
24
25 declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
26
27 impl<'tcx> LateLintPass<'tcx> for Pass {
28     fn check_crate(&mut self, cx: &LateContext) {
29         let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
30         let span = cx.tcx.def_span(CRATE_DEF_ID);
31         if !cx.sess().contains_name(attrs, Symbol::intern("crate_okay")) {
32             cx.lint(
33                 CRATE_NOT_OKAY,
34                 "crate is not marked with #![crate_okay]",
35                 |lint| lint.set_span(span)
36             );
37         }
38     }
39 }
40
41 #[no_mangle]
42 fn __rustc_plugin_registrar(reg: &mut Registry) {
43     reg.lint_store.register_lints(&[&CRATE_NOT_OKAY]);
44     reg.lint_store.register_late_pass(|_| Box::new(Pass));
45 }