17
17
use std:: marker:: PhantomData ;
18
18
19
19
use rustc_attr_data_structures:: AttributeKind ;
20
+ use rustc_feature:: AttributeTemplate ;
20
21
use rustc_session:: lint:: builtin:: UNUSED_ATTRIBUTES ;
21
22
use rustc_span:: { Span , Symbol } ;
22
23
use thin_vec:: ThinVec ;
@@ -36,7 +37,8 @@ pub(crate) mod transparency;
36
37
pub ( crate ) mod util;
37
38
38
39
type AcceptFn < T , S > = for <' sess > fn ( & mut T , & mut AcceptContext < ' _ , ' sess , S > , & ArgParser < ' _ > ) ;
39
- type AcceptMapping < T , S > = & ' static [ ( & ' static [ rustc_span:: Symbol ] , AcceptFn < T , S > ) ] ;
40
+ type AcceptMapping < T , S > =
41
+ & ' static [ ( & ' static [ rustc_span:: Symbol ] , AttributeTemplate , AcceptFn < T , S > ) ] ;
40
42
41
43
/// An [`AttributeParser`] is a type which searches for syntactic attributes.
42
44
///
@@ -79,6 +81,9 @@ pub(crate) trait SingleAttributeParser<S: Stage>: 'static {
79
81
const ATTRIBUTE_ORDER : AttributeOrder ;
80
82
const ON_DUPLICATE : OnDuplicate < S > ;
81
83
84
+ /// The template this attribute parser should implement. Used for diagnostics.
85
+ const TEMPLATE : AttributeTemplate ;
86
+
82
87
/// Converts a single syntactical attribute to a single semantic attribute, or [`AttributeKind`]
83
88
fn convert ( cx : & AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > ;
84
89
}
@@ -95,8 +100,10 @@ impl<T: SingleAttributeParser<S>, S: Stage> Default for Single<T, S> {
95
100
}
96
101
97
102
impl < T : SingleAttributeParser < S > , S : Stage > AttributeParser < S > for Single < T , S > {
98
- const ATTRIBUTES : AcceptMapping < Self , S > =
99
- & [ ( T :: PATH , |group : & mut Single < T , S > , cx, args| {
103
+ const ATTRIBUTES : AcceptMapping < Self , S > = & [ (
104
+ T :: PATH ,
105
+ <T as SingleAttributeParser < S > >:: TEMPLATE ,
106
+ |group : & mut Single < T , S > , cx, args| {
100
107
if let Some ( pa) = T :: convert ( cx, args) {
101
108
match T :: ATTRIBUTE_ORDER {
102
109
// keep the first and report immediately. ignore this attribute
@@ -117,7 +124,8 @@ impl<T: SingleAttributeParser<S>, S: Stage> AttributeParser<S> for Single<T, S>
117
124
118
125
group. 1 = Some ( ( pa, cx. attr_span ) ) ;
119
126
}
120
- } ) ] ;
127
+ } ,
128
+ ) ] ;
121
129
122
130
fn finalize ( self , _cx : & FinalizeContext < ' _ , ' _ , S > ) -> Option < AttributeKind > {
123
131
Some ( self . 1 ?. 0 )
@@ -216,6 +224,9 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
216
224
type Item ;
217
225
const CONVERT : ConvertFn < Self :: Item > ;
218
226
227
+ /// The template this attribute parser should implement. Used for diagnostics.
228
+ const TEMPLATE : AttributeTemplate ;
229
+
219
230
/// Converts a single syntactical attribute to a number of elements of the semantic attribute, or [`AttributeKind`]
220
231
fn extend < ' c > (
221
232
cx : & ' c mut AcceptContext < ' _ , ' _ , S > ,
@@ -235,8 +246,11 @@ impl<T: CombineAttributeParser<S>, S: Stage> Default for Combine<T, S> {
235
246
}
236
247
237
248
impl < T : CombineAttributeParser < S > , S : Stage > AttributeParser < S > for Combine < T , S > {
238
- const ATTRIBUTES : AcceptMapping < Self , S > =
239
- & [ ( T :: PATH , |group : & mut Combine < T , S > , cx, args| group. 1 . extend ( T :: extend ( cx, args) ) ) ] ;
249
+ const ATTRIBUTES : AcceptMapping < Self , S > = & [ (
250
+ T :: PATH ,
251
+ <T as CombineAttributeParser < S > >:: TEMPLATE ,
252
+ |group : & mut Combine < T , S > , cx, args| group. 1 . extend ( T :: extend ( cx, args) ) ,
253
+ ) ] ;
240
254
241
255
fn finalize ( self , _cx : & FinalizeContext < ' _ , ' _ , S > ) -> Option < AttributeKind > {
242
256
if self . 1 . is_empty ( ) { None } else { Some ( T :: CONVERT ( self . 1 ) ) }
0 commit comments