]> git.proxmox.com Git - rustc.git/blob - src/test/auxiliary/lint_for_crate.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / auxiliary / lint_for_crate.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // force-host
12
13 #![feature(plugin_registrar, rustc_private)]
14 #![feature(box_syntax)]
15
16 #[macro_use] extern crate rustc;
17 extern crate rustc_plugin;
18 extern crate syntax;
19
20 use rustc::lint::{LateContext, LintContext, LintPass, LateLintPass, LateLintPassObject, LintArray};
21 use rustc_plugin::Registry;
22 use rustc::hir;
23 use syntax::attr;
24
25 declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
26
27 struct Pass;
28
29 impl LintPass for Pass {
30 fn get_lints(&self) -> LintArray {
31 lint_array!(CRATE_NOT_OKAY)
32 }
33 }
34
35 impl LateLintPass for Pass {
36 fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
37 if !attr::contains_name(&krate.attrs, "crate_okay") {
38 cx.span_lint(CRATE_NOT_OKAY, krate.span,
39 "crate is not marked with #![crate_okay]");
40 }
41 }
42 }
43
44 #[plugin_registrar]
45 pub fn plugin_registrar(reg: &mut Registry) {
46 reg.register_late_lint_pass(box Pass as LateLintPassObject);
47 }