1 #![feature(box_syntax, plugin, plugin_registrar, rustc_private)]
2 #![crate_type = "dylib"]
4 extern crate rustc_ast_pretty
;
5 extern crate rustc_driver
;
6 extern crate rustc_hir
;
8 extern crate rustc_lint
;
10 extern crate rustc_session
;
11 extern crate rustc_span
;
12 extern crate rustc_ast
;
14 use rustc_ast_pretty
::pprust
;
15 use rustc_driver
::plugin
::Registry
;
17 use rustc_hir
::intravisit
;
19 use rustc_lint
::{LateContext, LateLintPass, LintArray, LintContext, LintPass}
;
20 use rustc_span
::source_map
;
23 pub fn plugin_registrar(reg
: &mut Registry
) {
24 reg
.lint_store
.register_lints(&[&MISSING_ALLOWED_ATTR
]);
25 reg
.lint_store
.register_late_pass(|| box MissingAllowedAttrPass
);
31 "Checks for missing `allowed_attr` attribute"
34 declare_lint_pass
!(MissingAllowedAttrPass
=> [MISSING_ALLOWED_ATTR
]);
36 impl<'tcx
> LateLintPass
<'tcx
> for MissingAllowedAttrPass
{
39 cx
: &LateContext
<'tcx
>,
40 _
: intravisit
::FnKind
<'tcx
>,
43 span
: source_map
::Span
,
46 let item
= match cx
.tcx
.hir().get(id
) {
47 Node
::Item(item
) => item
,
48 _
=> cx
.tcx
.hir().expect_item(cx
.tcx
.hir().get_parent_item(id
)),
51 let allowed
= |attr
| pprust
::attribute_to_string(attr
).contains("allowed_attr");
52 if !cx
.tcx
.hir().attrs(item
.hir_id()).iter().any(allowed
) {
53 cx
.lint(MISSING_ALLOWED_ATTR
, |lint
| {
54 lint
.build("Missing 'allowed_attr' attribute").set_span(span
).emit()