@@ -69,55 +69,48 @@ impl CheckAttrVisitor<'tcx> {
69
69
let mut is_valid = true ;
70
70
let attrs = self . tcx . hir ( ) . attrs ( hir_id) ;
71
71
for attr in attrs {
72
- is_valid &= if self . tcx . sess . check_name ( attr, sym:: inline) {
73
- self . check_inline ( hir_id, attr, span, target)
74
- } else if self . tcx . sess . check_name ( attr, sym:: non_exhaustive) {
75
- self . check_non_exhaustive ( hir_id, attr, span, target)
76
- } else if self . tcx . sess . check_name ( attr, sym:: marker) {
77
- self . check_marker ( hir_id, attr, span, target)
78
- } else if self . tcx . sess . check_name ( attr, sym:: target_feature) {
79
- self . check_target_feature ( hir_id, attr, span, target)
80
- } else if self . tcx . sess . check_name ( attr, sym:: track_caller) {
81
- self . check_track_caller ( hir_id, & attr. span , attrs, span, target)
82
- } else if self . tcx . sess . check_name ( attr, sym:: doc) {
83
- self . check_doc_attrs ( attr, hir_id, target)
84
- } else if self . tcx . sess . check_name ( attr, sym:: no_link) {
85
- self . check_no_link ( hir_id, & attr, span, target)
86
- } else if self . tcx . sess . check_name ( attr, sym:: export_name) {
87
- self . check_export_name ( hir_id, & attr, span, target)
88
- } else if self . tcx . sess . check_name ( attr, sym:: rustc_args_required_const) {
89
- self . check_rustc_args_required_const ( & attr, span, target, item)
90
- } else if self . tcx . sess . check_name ( attr, sym:: rustc_layout_scalar_valid_range_start) {
91
- self . check_rustc_layout_scalar_valid_range ( & attr, span, target)
92
- } else if self . tcx . sess . check_name ( attr, sym:: rustc_layout_scalar_valid_range_end) {
93
- self . check_rustc_layout_scalar_valid_range ( & attr, span, target)
94
- } else if self . tcx . sess . check_name ( attr, sym:: allow_internal_unstable) {
95
- self . check_allow_internal_unstable ( hir_id, & attr, span, target, & attrs)
96
- } else if self . tcx . sess . check_name ( attr, sym:: rustc_allow_const_fn_unstable) {
97
- self . check_rustc_allow_const_fn_unstable ( hir_id, & attr, span, target)
98
- } else if self . tcx . sess . check_name ( attr, sym:: naked) {
99
- self . check_naked ( hir_id, attr, span, target)
100
- } else if self . tcx . sess . check_name ( attr, sym:: rustc_legacy_const_generics) {
101
- self . check_rustc_legacy_const_generics ( & attr, span, target, item)
102
- } else if self . tcx . sess . check_name ( attr, sym:: rustc_clean)
103
- || self . tcx . sess . check_name ( attr, sym:: rustc_dirty)
104
- || self . tcx . sess . check_name ( attr, sym:: rustc_if_this_changed)
105
- || self . tcx . sess . check_name ( attr, sym:: rustc_then_this_would_need)
106
- {
107
- self . check_rustc_dirty_clean ( & attr)
108
- } else {
109
- // lint-only checks
110
- if self . tcx . sess . check_name ( attr, sym:: cold) {
111
- self . check_cold ( hir_id, attr, span, target) ;
112
- } else if self . tcx . sess . check_name ( attr, sym:: link_name) {
113
- self . check_link_name ( hir_id, attr, span, target) ;
114
- } else if self . tcx . sess . check_name ( attr, sym:: link_section) {
115
- self . check_link_section ( hir_id, attr, span, target) ;
116
- } else if self . tcx . sess . check_name ( attr, sym:: no_mangle) {
117
- self . check_no_mangle ( hir_id, attr, span, target) ;
72
+ is_valid &= match attr. name_or_empty ( ) {
73
+ sym:: inline => self . check_inline ( hir_id, attr, span, target) ,
74
+ sym:: non_exhaustive => self . check_non_exhaustive ( hir_id, attr, span, target) ,
75
+ sym:: marker => self . check_marker ( hir_id, attr, span, target) ,
76
+ sym:: target_feature => self . check_target_feature ( hir_id, attr, span, target) ,
77
+ sym:: track_caller => {
78
+ self . check_track_caller ( hir_id, & attr. span , attrs, span, target)
118
79
}
119
- true
80
+ sym:: doc => self . check_doc_attrs ( attr, hir_id, target) ,
81
+ sym:: no_link => self . check_no_link ( hir_id, & attr, span, target) ,
82
+ sym:: export_name => self . check_export_name ( hir_id, & attr, span, target) ,
83
+ sym:: rustc_args_required_const => {
84
+ self . check_rustc_args_required_const ( & attr, span, target, item)
85
+ }
86
+ sym:: rustc_layout_scalar_valid_range_start
87
+ | sym:: rustc_layout_scalar_valid_range_end => {
88
+ self . check_rustc_layout_scalar_valid_range ( & attr, span, target)
89
+ }
90
+ sym:: allow_internal_unstable => {
91
+ self . check_allow_internal_unstable ( hir_id, & attr, span, target, & attrs)
92
+ }
93
+ sym:: rustc_allow_const_fn_unstable => {
94
+ self . check_rustc_allow_const_fn_unstable ( hir_id, & attr, span, target)
95
+ }
96
+ sym:: naked => self . check_naked ( hir_id, attr, span, target) ,
97
+ sym:: rustc_legacy_const_generics => {
98
+ self . check_rustc_legacy_const_generics ( & attr, span, target, item)
99
+ }
100
+ sym:: rustc_clean
101
+ | sym:: rustc_dirty
102
+ | sym:: rustc_if_this_changed
103
+ | sym:: rustc_then_this_would_need => self . check_rustc_dirty_clean ( & attr) ,
104
+ _ => true ,
120
105
} ;
106
+ // lint-only checks
107
+ match attr. name_or_empty ( ) {
108
+ sym:: cold => self . check_cold ( hir_id, attr, span, target) ,
109
+ sym:: link_name => self . check_link_name ( hir_id, attr, span, target) ,
110
+ sym:: link_section => self . check_link_section ( hir_id, attr, span, target) ,
111
+ sym:: no_mangle => self . check_no_mangle ( hir_id, attr, span, target) ,
112
+ _ => { }
113
+ }
121
114
}
122
115
123
116
if !is_valid {
@@ -1116,7 +1109,7 @@ impl CheckAttrVisitor<'tcx> {
1116
1109
// ```
1117
1110
let hints: Vec < _ > = attrs
1118
1111
. iter ( )
1119
- . filter ( |attr| self . tcx . sess . check_name ( attr , sym:: repr) )
1112
+ . filter ( |attr| attr . has_name ( sym:: repr) )
1120
1113
. filter_map ( |attr| attr. meta_item_list ( ) )
1121
1114
. flatten ( )
1122
1115
. collect ( ) ;
@@ -1287,7 +1280,7 @@ impl CheckAttrVisitor<'tcx> {
1287
1280
1288
1281
fn check_used ( & self , attrs : & ' hir [ Attribute ] , target : Target ) {
1289
1282
for attr in attrs {
1290
- if self . tcx . sess . check_name ( attr , sym:: used) && target != Target :: Static {
1283
+ if attr . has_name ( sym:: used) && target != Target :: Static {
1291
1284
self . tcx
1292
1285
. sess
1293
1286
. span_err ( attr. span , "attribute must be applied to a `static` variable" ) ;
0 commit comments