@@ -166,20 +166,17 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
166
166
167
167
( "macro_reexport" , Normal ) ,
168
168
( "macro_use" , Normal ) ,
169
- ( "plugin" , Normal ) ,
170
169
( "macro_export" , Normal ) ,
171
170
( "plugin_registrar" , Normal ) ,
172
171
173
172
( "cfg" , Normal ) ,
174
173
( "main" , Normal ) ,
175
- ( "lang" , Normal ) ,
176
174
( "start" , Normal ) ,
177
175
( "test" , Normal ) ,
178
176
( "bench" , Normal ) ,
179
177
( "simd" , Normal ) ,
180
178
( "repr" , Normal ) ,
181
179
( "path" , Normal ) ,
182
- ( "staged_api" , Normal ) ,
183
180
( "abi" , Normal ) ,
184
181
( "rustc_move_fragments" , Normal ) ,
185
182
( "rustc_variance" , Normal ) ,
@@ -195,6 +192,17 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
195
192
( "link_args" , Normal ) ,
196
193
( "macro_escape" , Normal ) ,
197
194
195
+
196
+ ( "staged_api" , Gated ( "staged_api" ,
197
+ "staged_api is for use by rustc only" ) ) ,
198
+ ( "plugin" , Gated ( "plugin" ,
199
+ "compiler plugins are experimental \
200
+ and possibly buggy") ) ,
201
+ ( "no_std" , Gated ( "no_std" ,
202
+ "no_std is experimental" ) ) ,
203
+ ( "lang" , Gated ( "lang_items" ,
204
+ "language items are subject to change" ) ) ,
205
+
198
206
// FIXME: #14408 whitelist docs since rustdoc looks at them
199
207
( "doc" , Whitelisted ) ,
200
208
@@ -242,7 +250,6 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
242
250
( "feature" , CrateLevel ) ,
243
251
( "no_start" , CrateLevel ) ,
244
252
( "no_main" , CrateLevel ) ,
245
- ( "no_std" , CrateLevel ) ,
246
253
( "no_builtins" , CrateLevel ) ,
247
254
( "recursion_limit" , CrateLevel ) ,
248
255
] ;
@@ -258,6 +265,10 @@ pub enum AttributeType {
258
265
/// will be ignored by the unused_attribute lint
259
266
Whitelisted ,
260
267
268
+ /// Is gated by a given feature gate and reason
269
+ /// These get whitelisted too
270
+ Gated ( & ' static str , & ' static str ) ,
271
+
261
272
/// Builtin attribute that is only allowed at the crate level
262
273
CrateLevel ,
263
274
}
@@ -573,33 +584,22 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
573
584
}
574
585
575
586
fn visit_attribute ( & mut self , attr : & ast:: Attribute ) {
576
- match & * attr. name ( ) {
577
- "staged_api" => self . gate_feature ( "staged_api" , attr. span ,
578
- "staged_api is for use by rustc only" ) ,
579
- "plugin" => self . gate_feature ( "plugin" , attr. span ,
580
- "compiler plugins are experimental \
581
- and possibly buggy") ,
582
- "no_std" => self . gate_feature ( "no_std" , attr. span ,
583
- "no_std is experimental" ) ,
584
- "unsafe_no_drop_flag" => self . gate_feature ( "unsafe_no_drop_flag" , attr. span ,
585
- "unsafe_no_drop_flag has unstable \
586
- semantics and may be removed \
587
- in the future") ,
588
- "lang" => self . gate_feature ( "lang_items" ,
589
- attr. span ,
590
- "language items are subject to change" ) ,
591
- name => {
592
- // Custom attribute check
593
- if KNOWN_ATTRIBUTES . iter ( ) . all ( |& ( n, _) | n != name) {
594
- self . gate_feature ( "custom_attribute" , attr. span ,
595
- format ! ( "The attribute `{}` is currently \
596
- unknown to the the compiler and \
597
- may have meaning \
598
- added to it in the future",
599
- attr. name( ) ) . as_slice ( ) ) ;
587
+ let name = & * attr. name ( ) ;
588
+ for & ( n, ty) in KNOWN_ATTRIBUTES {
589
+ if n == name {
590
+ if let Gated ( gate, desc) = ty {
591
+ self . gate_feature ( gate, attr. span , desc) ;
600
592
}
593
+ return ;
601
594
}
595
+
602
596
}
597
+ self . gate_feature ( "custom_attribute" , attr. span ,
598
+ format ! ( "The attribute `{}` is currently \
599
+ unknown to the the compiler and \
600
+ may have meaning \
601
+ added to it in the future",
602
+ name) . as_slice ( ) ) ;
603
603
}
604
604
605
605
fn visit_pat ( & mut self , pattern : & ast:: Pat ) {
0 commit comments