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