]> git.lizzy.rs Git - rust.git/blob - src/attrs.rs
3ad3889f9db2537d6bb2fcbdd23b2d4d8e11b33d
[rust.git] / src / attrs.rs
1 /// checks for attributes
2
3 use rustc::plugin::Registry;
4 use rustc::lint::*;
5 use syntax::ast::*;
6 use syntax::ptr::P;
7 use syntax::codemap::Span;
8 use syntax::parse::token::InternedString;
9
10 declare_lint! { pub INLINE_ALWAYS, Warn,
11     "#[inline(always)] is usually a bad idea."}
12
13
14 #[derive(Copy,Clone)]
15 pub struct AttrPass;
16
17 impl LintPass for AttrPass {
18     fn get_lints(&self) -> LintArray {
19         lint_array!(INLINE_ALWAYS)
20     }
21     
22     fn check_item(&mut self, cx: &Context, item: &Item) {
23                 check_attrs(cx, &item.ident, &item.attrs)
24         }
25     
26     fn check_impl_item(&mut self, cx: &Context, item: &ImplItem) { 
27                 check_attrs(cx, &item.ident, &item.attrs)
28         }
29         
30         fn check_trait_item(&mut self, cx: &Context, item: &TraitItem) {
31                 check_attrs(cx, &item.ident, &item.attrs)
32         }
33 }
34
35 fn check_attrs(cx: &Context, ident: &Ident, attrs: &[Attribute]) {
36         for attr in attrs {
37                 if let MetaList(ref inline, ref values) = attr.node.value.node {
38                         if values.len() != 1 || inline != &"inline" { continue; }
39                         if let MetaWord(ref always) = values[0].node {
40                                 if always != &"always" { continue; }
41                                 cx.span_lint(INLINE_ALWAYS, attr.span, &format!(
42                                         "You have declared #[inline(always)] on {}. This \
43                                         is usually a bad idea. Are you sure?", 
44                                         ident.as_str()));
45                         }
46                 }
47         }
48 }