]> git.proxmox.com Git - rustc.git/blame - src/test/ui-fulldeps/auxiliary/lint-for-crate.rs
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / src / test / ui-fulldeps / auxiliary / lint-for-crate.rs
CommitLineData
c34b1796
AL
1// force-host
2
3#![feature(plugin_registrar, rustc_private)]
4#![feature(box_syntax)]
5
416331ca 6extern crate rustc_driver;
dfeec247 7extern crate rustc_hir;
74b04a01
XL
8#[macro_use]
9extern crate rustc_lint;
10#[macro_use]
11extern crate rustc_session;
dfeec247 12extern crate rustc_span;
74b04a01 13extern crate rustc_ast;
c34b1796 14
e1599b0c 15use rustc_driver::plugin::Registry;
74b04a01 16use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
dfeec247 17use rustc_span::symbol::Symbol;
74b04a01 18use rustc_ast::attr;
c34b1796 19
532ac7d7
XL
20declare_lint! {
21 CRATE_NOT_OKAY,
22 Warn,
23 "crate not marked with #![crate_okay]"
b039eaaf 24}
c34b1796 25
532ac7d7
XL
26declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
27
f035d41b 28impl<'tcx> LateLintPass<'tcx> for Pass {
dfeec247 29 fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
6a06907d
XL
30 let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
31 if !cx.sess().contains_name(attrs, Symbol::intern("crate_okay")) {
74b04a01
XL
32 cx.lint(CRATE_NOT_OKAY, |lint| {
33 lint.build("crate is not marked with #![crate_okay]")
ba9703b0 34 .set_span(krate.item.span)
74b04a01
XL
35 .emit()
36 });
c34b1796
AL
37 }
38 }
39}
40
41#[plugin_registrar]
42pub fn plugin_registrar(reg: &mut Registry) {
e74abb32
XL
43 reg.lint_store.register_lints(&[&CRATE_NOT_OKAY]);
44 reg.lint_store.register_late_pass(|| box Pass);
c34b1796 45}