diff options
| author | Trevor Gross <t.gross35@gmail.com> | 2025-06-20 13:35:59 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-20 13:35:59 -0400 |
| commit | d2a00eb65f7a35b56e15ce212b6f57d103a5a9e1 (patch) | |
| tree | 67fdbd7483227dd0dc51313e40790589b1a1f16a | |
| parent | f0374dced5375aa7e5e9e0ef497ff3992b77244d (diff) | |
| parent | 7f49de2cca902fe352cfba39f5e0f64b876f4524 (diff) | |
| download | rust-d2a00eb65f7a35b56e15ce212b6f57d103a5a9e1.tar.gz rust-d2a00eb65f7a35b56e15ce212b6f57d103a5a9e1.zip | |
Rollup merge of #142494 - jdonszelmann:missing-attr-parsing-docs, r=oli-obk
Fix missing docs in `rustc_attr_parsing`
| -rw-r--r-- | compiler/rustc_attr_parsing/src/attributes/mod.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/rustc_attr_parsing/src/attributes/mod.rs b/compiler/rustc_attr_parsing/src/attributes/mod.rs index 3bb4c163d32..78a696afa27 100644 --- a/compiler/rustc_attr_parsing/src/attributes/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/mod.rs @@ -87,8 +87,19 @@ pub(crate) trait AttributeParser<S: Stage>: Default + 'static { /// [`SingleAttributeParser`] can only convert attributes one-to-one, and cannot combine multiple /// attributes together like is necessary for `#[stable()]` and `#[unstable()]` for example. pub(crate) trait SingleAttributeParser<S: Stage>: 'static { + /// The single path of the attribute this parser accepts. + /// + /// If you need the parser to accept more than one path, use [`AttributeParser`] instead const PATH: &[Symbol]; + + /// Configures the precedence of attributes with the same `PATH` on a syntax node. const ATTRIBUTE_ORDER: AttributeOrder; + + /// Configures what to do when when the same attribute is + /// applied more than once on the same syntax node. + /// + /// [`ATTRIBUTE_ORDER`](Self::ATTRIBUTE_ORDER) specified which one is assumed to be correct, + /// and this specified whether to, for example, warn or error on the other one. const ON_DUPLICATE: OnDuplicate<S>; /// The template this attribute parser should implement. Used for diagnostics. @@ -98,6 +109,8 @@ pub(crate) trait SingleAttributeParser<S: Stage>: 'static { fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind>; } +/// Use in combination with [`SingleAttributeParser`]. +/// `Single<T: SingleAttributeParser>` implements [`AttributeParser`]. pub(crate) struct Single<T: SingleAttributeParser<S>, S: Stage>( PhantomData<(S, T)>, Option<(AttributeKind, Span)>, @@ -230,6 +243,10 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static { const PATH: &[rustc_span::Symbol]; type Item; + /// A function that converts individual items (of type [`Item`](Self::Item)) into the final attribute. + /// + /// For example, individual representations fomr `#[repr(...)]` attributes into an `AttributeKind::Repr(x)`, + /// where `x` is a vec of these individual reprs. const CONVERT: ConvertFn<Self::Item>; /// The template this attribute parser should implement. Used for diagnostics. @@ -242,6 +259,8 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static { ) -> impl IntoIterator<Item = Self::Item> + 'c; } +/// Use in combination with [`CombineAttributeParser`]. +/// `Combine<T: CombineAttributeParser>` implements [`AttributeParser`]. pub(crate) struct Combine<T: CombineAttributeParser<S>, S: Stage>( PhantomData<(S, T)>, ThinVec<<T as CombineAttributeParser<S>>::Item>, |
