@@ -85,8 +85,19 @@ pub(crate) trait AttributeParser<S: Stage>: Default + 'static {
85
85
/// [`SingleAttributeParser`] can only convert attributes one-to-one, and cannot combine multiple
86
86
/// attributes together like is necessary for `#[stable()]` and `#[unstable()]` for example.
87
87
pub ( crate ) trait SingleAttributeParser < S : Stage > : ' static {
88
+ /// The single path of the attribute this parser accepts.
89
+ ///
90
+ /// If you need the parser to accept more than one path, use [`AttributeParser`] instead
88
91
const PATH : & [ Symbol ] ;
92
+
93
+ /// Configures the precedence of attributes with the same `PATH` on a syntax node.
89
94
const ATTRIBUTE_ORDER : AttributeOrder ;
95
+
96
+ /// Configures what to do when when the same attribute is
97
+ /// applied more than once on the same syntax node.
98
+ ///
99
+ /// [`ATTRIBUTE_ORDER`] specified which one is assumed to be correct,
100
+ /// and this specified whether to, for example, warn or error on the other one.
90
101
const ON_DUPLICATE : OnDuplicate < S > ;
91
102
92
103
/// The template this attribute parser should implement. Used for diagnostics.
@@ -96,6 +107,8 @@ pub(crate) trait SingleAttributeParser<S: Stage>: 'static {
96
107
fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > ;
97
108
}
98
109
110
+ /// Use in combination with [`SingleAttributeParser`].
111
+ /// `Single<T: SingleAttributeParser>` implements [`AttributeParser`].
99
112
pub ( crate ) struct Single < T : SingleAttributeParser < S > , S : Stage > (
100
113
PhantomData < ( S , T ) > ,
101
114
Option < ( AttributeKind , Span ) > ,
@@ -228,6 +241,10 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
228
241
const PATH : & [ rustc_span:: Symbol ] ;
229
242
230
243
type Item ;
244
+ /// A function that converts individual items (of type [`Item`](Self::Item)) into the final attribute.
245
+ ///
246
+ /// For example, individual representations fomr `#[repr(...)]` attributes into an `AttributeKind::Repr(x)`,
247
+ /// where `x` is a vec of these individual reprs.
231
248
const CONVERT : ConvertFn < Self :: Item > ;
232
249
233
250
/// The template this attribute parser should implement. Used for diagnostics.
@@ -240,6 +257,8 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
240
257
) -> impl IntoIterator < Item = Self :: Item > + ' c ;
241
258
}
242
259
260
+ /// Use in combination with [`CombineAttributeParser`].
261
+ /// `Combine<T: CombineAttributeParser>` implements [`AttributeParser`].
243
262
pub ( crate ) struct Combine < T : CombineAttributeParser < S > , S : Stage > (
244
263
PhantomData < ( S , T ) > ,
245
264
ThinVec < <T as CombineAttributeParser < S > >:: Item > ,
0 commit comments