diff options
| author | Jana Dönszelmann <jana@donsz.nl> | 2025-06-11 16:10:47 +0200 |
|---|---|---|
| committer | Jana Dönszelmann <jana@donsz.nl> | 2025-06-11 18:46:57 +0200 |
| commit | 34241e539717e210a2a8336b28c7c0dbaceb2914 (patch) | |
| tree | 01e0e0c8ab439bdddd911cd6c36962f3bbbf4d31 | |
| parent | 8ce228758651aa58c4d34e3bd65bf70a251da27e (diff) | |
document attribute parsers better
| -rw-r--r-- | compiler/rustc_attr_parsing/src/attributes/mod.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_attr_parsing/src/attributes/mod.rs b/compiler/rustc_attr_parsing/src/attributes/mod.rs index bf18e10e19f..744f925e640 100644 --- a/compiler/rustc_attr_parsing/src/attributes/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/mod.rs @@ -51,6 +51,9 @@ type AcceptMapping<T> = &'static [(&'static [Symbol], AcceptFn<T>)]; /// whether it has seen the attribute it has been looking for. /// /// The state machine is automatically reset to parse attributes on the next item. +/// +/// For a simpler attribute parsing interface, consider using [`SingleAttributeParser`] +/// or [`CombineAttributeParser`] instead. pub(crate) trait AttributeParser: Default + 'static { /// The symbols for the attributes that this parser is interested in. /// @@ -59,6 +62,12 @@ pub(crate) trait AttributeParser: Default + 'static { /// The parser has gotten a chance to accept the attributes on an item, /// here it can produce an attribute. + /// + /// All finalize methods of all parsers are unconditionally called. + /// This means you can't unconditionally return `Some` here, + /// that'd be equivalent to unconditionally applying an attribute to + /// every single syntax item that could have attributes applied to it. + /// Your accept mappings should determine whether this returns something. fn finalize(self, cx: &FinalizeContext<'_>) -> Option<AttributeKind>; } |
