]> git.proxmox.com Git - rustc.git/blame - src/test/ui-fulldeps/auxiliary/lint-for-crate.rs
New upstream version 1.42.0+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
XL
7extern crate rustc_hir;
8#[macro_use] extern crate rustc_lint;
9#[macro_use] extern crate rustc_session;
10extern crate rustc_span;
b039eaaf 11extern crate syntax;
c34b1796 12
dfeec247 13use rustc_lint::{LateContext, LintContext, LintPass, LateLintPass, LintArray};
e1599b0c 14use rustc_driver::plugin::Registry;
dfeec247 15use rustc_span::symbol::Symbol;
b039eaaf 16use syntax::attr;
c34b1796 17
532ac7d7
XL
18declare_lint! {
19 CRATE_NOT_OKAY,
20 Warn,
21 "crate not marked with #![crate_okay]"
b039eaaf 22}
c34b1796 23
532ac7d7
XL
24declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
25
476ff2be 26impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
dfeec247 27 fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
48663c56 28 if !attr::contains_name(&krate.attrs, Symbol::intern("crate_okay")) {
c34b1796
AL
29 cx.span_lint(CRATE_NOT_OKAY, krate.span,
30 "crate is not marked with #![crate_okay]");
31 }
32 }
33}
34
35#[plugin_registrar]
36pub fn plugin_registrar(reg: &mut Registry) {
e74abb32
XL
37 reg.lint_store.register_lints(&[&CRATE_NOT_OKAY]);
38 reg.lint_store.register_late_pass(|| box Pass);
c34b1796 39}