@@ -3,27 +3,32 @@ use rustc_hir::attrs::{AttributeKind, CoverageAttrKind, OptimizeAttr, UsedBy};
3
3
use rustc_hir:: { MethodKind , Target } ;
4
4
use rustc_session:: parse:: feature_err;
5
5
use rustc_span:: { Span , Symbol , sym} ;
6
-
6
+ use crate :: context:: AllowedTargets ;
7
+ use crate :: context:: MaybeWarn :: Allow ;
7
8
use super :: {
8
9
AcceptMapping , AttributeOrder , AttributeParser , CombineAttributeParser , ConvertFn ,
9
10
NoArgsAttributeParser , OnDuplicate , SingleAttributeParser ,
10
11
} ;
11
12
use crate :: context:: { AcceptContext , FinalizeContext , Stage } ;
13
+ use crate :: context:: AllowedTargets ;
14
+ use crate :: context:: MaybeWarn :: Allow ;
12
15
use crate :: parser:: ArgParser ;
13
16
use crate :: session_diagnostics:: { NakedFunctionIncompatibleAttribute , NullOnExport } ;
17
+ use crate :: context:: AllowedTargets ;
18
+ use crate :: context:: MaybeWarn :: Allow ;
14
19
15
20
pub ( crate ) struct OptimizeParser ;
16
21
17
22
impl < S : Stage > SingleAttributeParser < S > for OptimizeParser {
18
23
const PATH : & [ Symbol ] = & [ sym:: optimize] ;
19
24
const ATTRIBUTE_ORDER : AttributeOrder = AttributeOrder :: KeepOutermost ;
20
25
const ON_DUPLICATE : OnDuplicate < S > = OnDuplicate :: WarnButFutureError ;
21
- const ALLOWED_TARGETS : & ' static [ Target ] = & [
22
- Target :: Fn ,
23
- Target :: Closure ,
24
- Target :: Method ( MethodKind :: Trait { body : true } ) ,
25
- Target :: Method ( MethodKind :: Inherent ) ,
26
- ] ;
26
+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( & [
27
+ Allow ( Target :: Fn ) ,
28
+ Allow ( Target :: Closure ) ,
29
+ Allow ( Target :: Method ( MethodKind :: Trait { body : true } ) ) ,
30
+ Allow ( Target :: Method ( MethodKind :: Inherent ) ) ,
31
+ ] ) ;
27
32
const TEMPLATE : AttributeTemplate = template ! ( List : "size|speed|none" ) ;
28
33
29
34
fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
@@ -56,14 +61,14 @@ pub(crate) struct ColdParser;
56
61
impl < S : Stage > NoArgsAttributeParser < S > for ColdParser {
57
62
const PATH : & [ Symbol ] = & [ sym:: cold] ;
58
63
const ON_DUPLICATE : OnDuplicate < S > = OnDuplicate :: Warn ;
59
- const ALLOWED_TARGETS : & ' static [ Target ] = & [
60
- Target :: Fn ,
61
- Target :: Method ( MethodKind :: Trait { body : true } ) ,
62
- Target :: Method ( MethodKind :: Trait { body : false } ) ,
63
- Target :: Method ( MethodKind :: Inherent ) ,
64
- Target :: ForeignFn ,
65
- Target :: Closure ,
66
- ] ;
64
+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( & [
65
+ Allow ( Target :: Fn ) ,
66
+ Allow ( Target :: Method ( MethodKind :: Trait { body : true } ) ) ,
67
+ Allow ( Target :: Method ( MethodKind :: Trait { body : false } ) ) ,
68
+ Allow ( Target :: Method ( MethodKind :: Inherent ) ) ,
69
+ Allow ( Target :: ForeignFn ) ,
70
+ Allow ( Target :: Closure ) ,
71
+ ] ) ;
67
72
const CREATE : fn ( Span ) -> AttributeKind = AttributeKind :: Cold ;
68
73
}
69
74
@@ -73,15 +78,15 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
73
78
const PATH : & [ Symbol ] = & [ sym:: coverage] ;
74
79
const ATTRIBUTE_ORDER : AttributeOrder = AttributeOrder :: KeepOutermost ;
75
80
const ON_DUPLICATE : OnDuplicate < S > = OnDuplicate :: Error ;
76
- const ALLOWED_TARGETS : & ' static [ Target ] = & [
77
- Target :: Fn ,
78
- Target :: Closure ,
79
- Target :: Method ( MethodKind :: Trait { body : true } ) ,
80
- Target :: Method ( MethodKind :: Inherent ) ,
81
+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( & [
82
+ Allow ( Target :: Fn ) ,
83
+ Allow ( Target :: Closure ) ,
84
+ Allow ( Target :: Method ( MethodKind :: Trait { body : true } ) ) ,
85
+ Allow ( Target :: Method ( MethodKind :: Inherent ) ) ,
81
86
Target :: Impl { of_trait : true } ,
82
87
Target :: Impl { of_trait : false } ,
83
88
Target :: Mod ,
84
- ] ;
89
+ ] ) ;
85
90
const TEMPLATE : AttributeTemplate = template ! ( OneOf : & [ sym:: off, sym:: on] ) ;
86
91
87
92
fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
@@ -121,8 +126,8 @@ impl<S: Stage> SingleAttributeParser<S> for ExportNameParser {
121
126
const PATH : & [ rustc_span:: Symbol ] = & [ sym:: export_name] ;
122
127
const ATTRIBUTE_ORDER : AttributeOrder = AttributeOrder :: KeepInnermost ;
123
128
const ON_DUPLICATE : OnDuplicate < S > = OnDuplicate :: WarnButFutureError ;
124
- const ALLOWED_TARGETS : & ' static [ Target ] =
125
- & [ Target :: Static , Target :: Fn , Target :: Method ( MethodKind :: Inherent ) ] ;
129
+ const ALLOWED_TARGETS : AllowedTargets =
130
+ & [ Target :: Static , Target :: Fn , Target :: Method ( MethodKind :: Inherent ) , Target :: Method ( MethodKind :: Trait { body : true } ) ] ;
126
131
const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "name" ) ;
127
132
128
133
fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
@@ -164,11 +169,11 @@ impl<S: Stage> AttributeParser<S> for NakedParser {
164
169
this. span = Some ( cx. attr_span ) ;
165
170
}
166
171
} ) ] ;
167
- const ALLOWED_TARGETS : & ' static [ Target ] = & [
172
+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( & [
168
173
Target :: Fn ,
169
174
Target :: Method ( MethodKind :: Inherent ) ,
170
175
Target :: Method ( MethodKind :: Trait { body : true } ) ,
171
- ] ;
176
+ ] ) ;
172
177
173
178
fn finalize ( self , cx : & FinalizeContext < ' _ , ' _ , S > ) -> Option < AttributeKind > {
174
179
// FIXME(jdonszelmann): upgrade this list to *parsed* attributes
@@ -261,22 +266,22 @@ pub(crate) struct TrackCallerParser;
261
266
impl < S : Stage > NoArgsAttributeParser < S > for TrackCallerParser {
262
267
const PATH : & [ Symbol ] = & [ sym:: track_caller] ;
263
268
const ON_DUPLICATE : OnDuplicate < S > = OnDuplicate :: Warn ;
264
- const ALLOWED_TARGETS : & ' static [ Target ] = & [
269
+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( & [
265
270
Target :: Fn ,
266
271
Target :: Method ( MethodKind :: Inherent ) ,
267
272
Target :: Method ( MethodKind :: Trait { body : true } ) ,
268
273
Target :: Method ( MethodKind :: Trait { body : false } ) ,
269
274
Target :: ForeignFn ,
270
275
Target :: Closure ,
271
- ] ;
276
+ ] ) ;
272
277
const CREATE : fn ( Span ) -> AttributeKind = AttributeKind :: TrackCaller ;
273
278
}
274
279
275
280
pub ( crate ) struct NoMangleParser ;
276
281
impl < S : Stage > NoArgsAttributeParser < S > for NoMangleParser {
277
282
const PATH : & [ Symbol ] = & [ sym:: no_mangle] ;
278
283
const ON_DUPLICATE : OnDuplicate < S > = OnDuplicate :: Warn ;
279
- const ALLOWED_TARGETS : & ' static [ Target ] = & [ Target :: Fn , Target :: Static ] ;
284
+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( & [ Target :: Fn , Target :: Static , Target :: Method ( MethodKind :: Inherent ) , Target :: Method ( MethodKind :: Trait { body : true } ) ] ) ;
280
285
const CREATE : fn ( Span ) -> AttributeKind = AttributeKind :: NoMangle ;
281
286
}
282
287
@@ -350,7 +355,7 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
350
355
}
351
356
} ,
352
357
) ] ;
353
- const ALLOWED_TARGETS : & ' static [ Target ] = & [ Target :: Static ] ;
358
+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( & [ Target :: Static ] ) ;
354
359
355
360
fn finalize ( self , _cx : & FinalizeContext < ' _ , ' _ , S > ) -> Option < AttributeKind > {
356
361
// Ratcheting behaviour, if both `linker` and `compiler` are specified, use `linker`
@@ -415,5 +420,5 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
415
420
features
416
421
}
417
422
418
- const ALLOWED_TARGETS : & ' static [ Target ] = & [ Target :: Fn , Target :: Method ( MethodKind :: Inherent ) ] ;
423
+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( & [ Target :: Fn , Target :: Method ( MethodKind :: Inherent ) ] ) ;
419
424
}
0 commit comments