3 #![feature(rustc_private)]
5 extern crate rustc_driver;
6 extern crate rustc_hir;
8 extern crate rustc_lint;
10 extern crate rustc_session;
11 extern crate rustc_ast;
12 extern crate rustc_span;
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;
22 "crate not marked with #![crate_okay]"
25 declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
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(CRATE_NOT_OKAY, |lint| {
33 lint.build("crate is not marked with #![crate_okay]").set_span(span).emit();
40 fn __rustc_plugin_registrar(reg: &mut Registry) {
41 reg.lint_store.register_lints(&[&CRATE_NOT_OKAY]);
42 reg.lint_store.register_late_pass(|| Box::new(Pass));