@@ -57,7 +57,7 @@ struct CheckAttrVisitor<'a> {
57
57
58
58
impl < ' a > CheckAttrVisitor < ' a > {
59
59
/// Check any attribute.
60
- fn check_attribute ( & self , attr : & ast:: Attribute , item : & ast:: Item , target : Target ) {
60
+ fn check_attribute ( & self , attr : & ast:: Attribute , item : Option < & ast:: Item > , target : Target ) {
61
61
if let Some ( name) = attr. name ( ) {
62
62
match & * name. as_str ( ) {
63
63
"inline" => self . check_inline ( attr, item, target) ,
@@ -68,10 +68,10 @@ impl<'a> CheckAttrVisitor<'a> {
68
68
}
69
69
70
70
/// Check if an `#[inline]` is applied to a function.
71
- fn check_inline ( & self , attr : & ast:: Attribute , item : & ast:: Item , target : Target ) {
71
+ fn check_inline ( & self , attr : & ast:: Attribute , _item : Option < & ast:: Item > , target : Target ) {
72
72
if target != Target :: Fn {
73
73
struct_span_err ! ( self . sess, attr. span, E0518 , "attribute should be applied to function" )
74
- . span_label ( item . span , "not a function" )
74
+ . span_label ( attr . span , "not a function" )
75
75
. emit ( ) ;
76
76
}
77
77
if :: std:: env:: var_os ( "ATTR" ) . is_some ( ) {
@@ -85,7 +85,7 @@ impl<'a> CheckAttrVisitor<'a> {
85
85
}
86
86
87
87
/// Check if an `#[repr]` attr is valid.
88
- fn check_repr ( & self , attr : & ast:: Attribute , item : & ast:: Item , target : Target ) {
88
+ fn check_repr ( & self , attr : & ast:: Attribute , item : Option < & ast:: Item > , target : Target ) {
89
89
let words = match attr. meta_item_list ( ) {
90
90
Some ( words) => words,
91
91
None => {
@@ -157,7 +157,7 @@ impl<'a> CheckAttrVisitor<'a> {
157
157
_ => continue ,
158
158
} ;
159
159
struct_span_err ! ( self . sess, attr. span, E0517 , "{}" , message)
160
- . span_label ( item. span , format ! ( "not {}" , label) )
160
+ . span_label ( item. unwrap ( ) . span , format ! ( "not {}" , label) )
161
161
. emit ( ) ;
162
162
}
163
163
if conflicting_reprs > 1 {
@@ -171,23 +171,23 @@ impl<'a> Visitor<'a> for CheckAttrVisitor<'a> {
171
171
fn visit_item ( & mut self , item : & ' a ast:: Item ) {
172
172
let target = Target :: from_item ( item) ;
173
173
for attr in & item. attrs {
174
- self . check_attribute ( attr, item, target) ;
174
+ self . check_attribute ( attr, Some ( item) , target) ;
175
175
}
176
176
visit:: walk_item ( self , item) ;
177
177
}
178
178
179
179
fn visit_trait_item ( & mut self , item : & ' a ast:: TraitItem ) {
180
180
let target = Target :: from_trait_item ( item) ;
181
181
for attr in & item. attrs {
182
- self . check_attribute ( attr, target) ;
182
+ self . check_attribute ( attr, None /*item*/ , target) ;
183
183
}
184
184
visit:: walk_trait_item ( self , item) ;
185
185
}
186
186
187
187
fn visit_impl_item ( & mut self , item : & ' a ast:: ImplItem ) {
188
188
let target = Target :: from_impl_item ( item) ;
189
189
for attr in & item. attrs {
190
- self . check_attribute ( attr, target) ;
190
+ self . check_attribute ( attr, None /*item*/ , target) ;
191
191
}
192
192
visit:: walk_impl_item ( self , item) ;
193
193
}
0 commit comments