1 // Copyright 2016 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.
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 #![feature(box_syntax, plugin, plugin_registrar, rustc_private)]
11 #![crate_type = "dylib"]
15 extern crate rustc_plugin
;
18 use rustc_plugin
::Registry
;
19 use syntax
::ext
::base
::*;
20 use syntax
::feature_gate
::AttributeType
::Whitelisted
;
21 use syntax
::symbol
::Symbol
;
24 use rustc
::hir
::intravisit
;
25 use rustc
::hir
::map
as hir_map
;
26 use rustc
::lint
::{LateContext, LintPass, LintArray, LateLintPass, LintContext}
;
28 use syntax
::{ast, codemap}
;
31 pub fn plugin_registrar(reg
: &mut Registry
) {
32 reg
.register_late_lint_pass(box MissingWhitelistedAttrPass
);
33 reg
.register_attribute("whitelisted_attr".to_string(), Whitelisted
);
36 declare_lint
!(MISSING_WHITELISTED_ATTR
, Deny
,
37 "Checks for missing `whitelisted_attr` attribute");
39 struct MissingWhitelistedAttrPass
;
41 impl LintPass
for MissingWhitelistedAttrPass
{
42 fn get_lints(&self) -> LintArray
{
43 lint_array
!(MISSING_WHITELISTED_ATTR
)
47 impl<'a
, 'tcx
> LateLintPass
<'a
, 'tcx
> for MissingWhitelistedAttrPass
{
48 fn check_fn(&mut self,
49 cx
: &LateContext
<'a
, 'tcx
>,
50 _
: intravisit
::FnKind
<'tcx
>,
56 let item
= match cx
.tcx
.hir
.get(id
) {
57 hir_map
::Node
::NodeItem(item
) => item
,
58 _
=> cx
.tcx
.hir
.expect_item(cx
.tcx
.hir
.get_parent(id
)),
61 if !item
.attrs
.iter().any(|a
| a
.check_name("whitelisted_attr")) {
62 cx
.span_lint(MISSING_WHITELISTED_ATTR
, span
,
63 "Missing 'whitelited_attr' attribute");