8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ //! This module implements some validity checks for attributes.
12
+ //! In particular it verifies that `#[inline]` and `#[repr]` attributes are
13
+ //! attached to items that actually support them and if there are
14
+ //! conflicts between multiple such attributes attached to the same
15
+ //! item.
16
+
11
17
use session:: Session ;
12
18
13
19
use syntax:: ast;
@@ -40,6 +46,18 @@ struct CheckAttrVisitor<'a> {
40
46
}
41
47
42
48
impl < ' a > CheckAttrVisitor < ' a > {
49
+ /// Check any attribute.
50
+ fn check_attribute ( & self , attr : & ast:: Attribute , target : Target ) {
51
+ if let Some ( name) = attr. name ( ) {
52
+ match & * name. as_str ( ) {
53
+ "inline" => self . check_inline ( attr, target) ,
54
+ "repr" => self . check_repr ( attr, target) ,
55
+ _ => ( ) ,
56
+ }
57
+ }
58
+ }
59
+
60
+ /// Check if an `#[inline]` is applied to a function.
43
61
fn check_inline ( & self , attr : & ast:: Attribute , target : Target ) {
44
62
if target != Target :: Fn {
45
63
struct_span_err ! ( self . sess, attr. span, E0518 , "attribute should be applied to function" )
@@ -48,6 +66,7 @@ impl<'a> CheckAttrVisitor<'a> {
48
66
}
49
67
}
50
68
69
+ /// Check if an `#[repr]` attr is valid.
51
70
fn check_repr ( & self , attr : & ast:: Attribute , target : Target ) {
52
71
let words = match attr. meta_item_list ( ) {
53
72
Some ( words) => words,
@@ -135,16 +154,6 @@ impl<'a> CheckAttrVisitor<'a> {
135
154
"conflicting packed and align representation hints" ) . emit ( ) ;
136
155
}
137
156
}
138
-
139
- fn check_attribute ( & self , attr : & ast:: Attribute , target : Target ) {
140
- if let Some ( name) = attr. name ( ) {
141
- match & * name. as_str ( ) {
142
- "inline" => self . check_inline ( attr, target) ,
143
- "repr" => self . check_repr ( attr, target) ,
144
- _ => ( ) ,
145
- }
146
- }
147
- }
148
157
}
149
158
150
159
impl < ' a > Visitor < ' a > for CheckAttrVisitor < ' a > {
0 commit comments