@@ -62,12 +62,12 @@ impl CheckAttrVisitor<'tcx> {
62
62
fn check_attributes (
63
63
& self ,
64
64
hir_id : HirId ,
65
- attrs : & ' hir [ Attribute ] ,
66
65
span : & Span ,
67
66
target : Target ,
68
67
item : Option < ItemLike < ' _ > > ,
69
68
) {
70
69
let mut is_valid = true ;
70
+ let attrs = self . tcx . hir ( ) . attrs ( hir_id) ;
71
71
for attr in attrs {
72
72
is_valid &= if self . tcx . sess . check_name ( attr, sym:: inline) {
73
73
self . check_inline ( hir_id, attr, span, target)
@@ -1213,61 +1213,36 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
1213
1213
1214
1214
fn visit_item ( & mut self , item : & ' tcx Item < ' tcx > ) {
1215
1215
let target = Target :: from_item ( item) ;
1216
- self . check_attributes (
1217
- item. hir_id ( ) ,
1218
- item. attrs ,
1219
- & item. span ,
1220
- target,
1221
- Some ( ItemLike :: Item ( item) ) ,
1222
- ) ;
1216
+ self . check_attributes ( item. hir_id ( ) , & item. span , target, Some ( ItemLike :: Item ( item) ) ) ;
1223
1217
intravisit:: walk_item ( self , item)
1224
1218
}
1225
1219
1226
1220
fn visit_generic_param ( & mut self , generic_param : & ' tcx hir:: GenericParam < ' tcx > ) {
1227
1221
let target = Target :: from_generic_param ( generic_param) ;
1228
- self . check_attributes (
1229
- generic_param. hir_id ,
1230
- generic_param. attrs ,
1231
- & generic_param. span ,
1232
- target,
1233
- None ,
1234
- ) ;
1222
+ self . check_attributes ( generic_param. hir_id , & generic_param. span , target, None ) ;
1235
1223
intravisit:: walk_generic_param ( self , generic_param)
1236
1224
}
1237
1225
1238
1226
fn visit_trait_item ( & mut self , trait_item : & ' tcx TraitItem < ' tcx > ) {
1239
1227
let target = Target :: from_trait_item ( trait_item) ;
1240
- self . check_attributes (
1241
- trait_item. hir_id ( ) ,
1242
- & trait_item. attrs ,
1243
- & trait_item. span ,
1244
- target,
1245
- None ,
1246
- ) ;
1228
+ self . check_attributes ( trait_item. hir_id ( ) , & trait_item. span , target, None ) ;
1247
1229
intravisit:: walk_trait_item ( self , trait_item)
1248
1230
}
1249
1231
1250
1232
fn visit_struct_field ( & mut self , struct_field : & ' tcx hir:: StructField < ' tcx > ) {
1251
- self . check_attributes (
1252
- struct_field. hir_id ,
1253
- & struct_field. attrs ,
1254
- & struct_field. span ,
1255
- Target :: Field ,
1256
- None ,
1257
- ) ;
1233
+ self . check_attributes ( struct_field. hir_id , & struct_field. span , Target :: Field , None ) ;
1258
1234
intravisit:: walk_struct_field ( self , struct_field) ;
1259
1235
}
1260
1236
1261
1237
fn visit_arm ( & mut self , arm : & ' tcx hir:: Arm < ' tcx > ) {
1262
- self . check_attributes ( arm. hir_id , & arm. attrs , & arm . span , Target :: Arm , None ) ;
1238
+ self . check_attributes ( arm. hir_id , & arm. span , Target :: Arm , None ) ;
1263
1239
intravisit:: walk_arm ( self , arm) ;
1264
1240
}
1265
1241
1266
1242
fn visit_foreign_item ( & mut self , f_item : & ' tcx ForeignItem < ' tcx > ) {
1267
1243
let target = Target :: from_foreign_item ( f_item) ;
1268
1244
self . check_attributes (
1269
1245
f_item. hir_id ( ) ,
1270
- & f_item. attrs ,
1271
1246
& f_item. span ,
1272
1247
target,
1273
1248
Some ( ItemLike :: ForeignItem ( f_item) ) ,
@@ -1277,14 +1252,14 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
1277
1252
1278
1253
fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem < ' tcx > ) {
1279
1254
let target = target_from_impl_item ( self . tcx , impl_item) ;
1280
- self . check_attributes ( impl_item. hir_id ( ) , & impl_item. attrs , & impl_item . span , target, None ) ;
1255
+ self . check_attributes ( impl_item. hir_id ( ) , & impl_item. span , target, None ) ;
1281
1256
intravisit:: walk_impl_item ( self , impl_item)
1282
1257
}
1283
1258
1284
1259
fn visit_stmt ( & mut self , stmt : & ' tcx hir:: Stmt < ' tcx > ) {
1285
1260
// When checking statements ignore expressions, they will be checked later.
1286
1261
if let hir:: StmtKind :: Local ( ref l) = stmt. kind {
1287
- self . check_attributes ( l. hir_id , & l . attrs , & stmt. span , Target :: Statement , None ) ;
1262
+ self . check_attributes ( l. hir_id , & stmt. span , Target :: Statement , None ) ;
1288
1263
}
1289
1264
intravisit:: walk_stmt ( self , stmt)
1290
1265
}
@@ -1295,7 +1270,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
1295
1270
_ => Target :: Expression ,
1296
1271
} ;
1297
1272
1298
- self . check_attributes ( expr. hir_id , & expr. attrs , & expr . span , target, None ) ;
1273
+ self . check_attributes ( expr. hir_id , & expr. span , target, None ) ;
1299
1274
intravisit:: walk_expr ( self , expr)
1300
1275
}
1301
1276
@@ -1305,23 +1280,17 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
1305
1280
generics : & ' tcx hir:: Generics < ' tcx > ,
1306
1281
item_id : HirId ,
1307
1282
) {
1308
- self . check_attributes ( variant. id , variant . attrs , & variant. span , Target :: Variant , None ) ;
1283
+ self . check_attributes ( variant. id , & variant. span , Target :: Variant , None ) ;
1309
1284
intravisit:: walk_variant ( self , variant, generics, item_id)
1310
1285
}
1311
1286
1312
1287
fn visit_macro_def ( & mut self , macro_def : & ' tcx hir:: MacroDef < ' tcx > ) {
1313
- self . check_attributes (
1314
- macro_def. hir_id ( ) ,
1315
- macro_def. attrs ,
1316
- & macro_def. span ,
1317
- Target :: MacroDef ,
1318
- None ,
1319
- ) ;
1288
+ self . check_attributes ( macro_def. hir_id ( ) , & macro_def. span , Target :: MacroDef , None ) ;
1320
1289
intravisit:: walk_macro_def ( self , macro_def) ;
1321
1290
}
1322
1291
1323
1292
fn visit_param ( & mut self , param : & ' tcx hir:: Param < ' tcx > ) {
1324
- self . check_attributes ( param. hir_id , param . attrs , & param. span , Target :: Param , None ) ;
1293
+ self . check_attributes ( param. hir_id , & param. span , Target :: Param , None ) ;
1325
1294
1326
1295
intravisit:: walk_param ( self , param) ;
1327
1296
}
@@ -1389,13 +1358,7 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
1389
1358
tcx. hir ( ) . visit_exported_macros_in_krate ( check_attr_visitor) ;
1390
1359
check_invalid_macro_level_attr ( tcx, tcx. hir ( ) . krate ( ) . non_exported_macro_attrs ) ;
1391
1360
if module_def_id. is_top_level_module ( ) {
1392
- check_attr_visitor. check_attributes (
1393
- CRATE_HIR_ID ,
1394
- tcx. hir ( ) . krate_attrs ( ) ,
1395
- & DUMMY_SP ,
1396
- Target :: Mod ,
1397
- None ,
1398
- ) ;
1361
+ check_attr_visitor. check_attributes ( CRATE_HIR_ID , & DUMMY_SP , Target :: Mod , None ) ;
1399
1362
check_invalid_crate_level_attr ( tcx, tcx. hir ( ) . krate_attrs ( ) ) ;
1400
1363
}
1401
1364
}
0 commit comments