1717use std:: marker:: PhantomData ;
1818
1919use rustc_attr_data_structures:: AttributeKind ;
20+ use rustc_feature:: AttributeTemplate ;
2021use rustc_session:: lint:: builtin:: UNUSED_ATTRIBUTES ;
2122use rustc_span:: { Span , Symbol } ;
2223use thin_vec:: ThinVec ;
@@ -36,7 +37,8 @@ pub(crate) mod transparency;
3637pub ( crate ) mod util;
3738
3839type 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 > ) ] ;
4042
4143/// An [`AttributeParser`] is a type which searches for syntactic attributes.
4244///
@@ -79,6 +81,9 @@ pub(crate) trait SingleAttributeParser<S: Stage>: 'static {
7981 const ATTRIBUTE_ORDER : AttributeOrder ;
8082 const ON_DUPLICATE : OnDuplicate < S > ;
8183
84+ /// The template this attribute parser should implement. Used for diagnostics.
85+ const TEMPLATE : AttributeTemplate ;
86+
8287 /// Converts a single syntactical attribute to a single semantic attribute, or [`AttributeKind`]
8388 fn convert ( cx : & AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > ;
8489}
@@ -95,8 +100,10 @@ impl<T: SingleAttributeParser<S>, S: Stage> Default for Single<T, S> {
95100}
96101
97102impl < 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| {
100107 if let Some ( pa) = T :: convert ( cx, args) {
101108 match T :: ATTRIBUTE_ORDER {
102109 // 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>
117124
118125 group. 1 = Some ( ( pa, cx. attr_span ) ) ;
119126 }
120- } ) ] ;
127+ } ,
128+ ) ] ;
121129
122130 fn finalize ( self , _cx : & FinalizeContext < ' _ , ' _ , S > ) -> Option < AttributeKind > {
123131 Some ( self . 1 ?. 0 )
@@ -216,6 +224,9 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
216224 type Item ;
217225 const CONVERT : ConvertFn < Self :: Item > ;
218226
227+ /// The template this attribute parser should implement. Used for diagnostics.
228+ const TEMPLATE : AttributeTemplate ;
229+
219230 /// Converts a single syntactical attribute to a number of elements of the semantic attribute, or [`AttributeKind`]
220231 fn extend < ' c > (
221232 cx : & ' c mut AcceptContext < ' _ , ' _ , S > ,
@@ -235,8 +246,11 @@ impl<T: CombineAttributeParser<S>, S: Stage> Default for Combine<T, S> {
235246}
236247
237248impl < 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+ ) ] ;
240254
241255 fn finalize ( self , _cx : & FinalizeContext < ' _ , ' _ , S > ) -> Option < AttributeKind > {
242256 if self . 1 . is_empty ( ) { None } else { Some ( T :: CONVERT ( self . 1 ) ) }
0 commit comments