Skip to content

Commit 34241e5

Browse files
committed
document attribute parsers better
1 parent 8ce2287 commit 34241e5

File tree

1 file changed

+9
-0
lines changed
  • compiler/rustc_attr_parsing/src/attributes

1 file changed

+9
-0
lines changed

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ type AcceptMapping<T> = &'static [(&'static [Symbol], AcceptFn<T>)];
5151
/// whether it has seen the attribute it has been looking for.
5252
///
5353
/// The state machine is automatically reset to parse attributes on the next item.
54+
///
55+
/// For a simpler attribute parsing interface, consider using [`SingleAttributeParser`]
56+
/// or [`CombineAttributeParser`] instead.
5457
pub(crate) trait AttributeParser: Default + 'static {
5558
/// The symbols for the attributes that this parser is interested in.
5659
///
@@ -59,6 +62,12 @@ pub(crate) trait AttributeParser: Default + 'static {
5962

6063
/// The parser has gotten a chance to accept the attributes on an item,
6164
/// here it can produce an attribute.
65+
///
66+
/// All finalize methods of all parsers are unconditionally called.
67+
/// This means you can't unconditionally return `Some` here,
68+
/// that'd be equivalent to unconditionally applying an attribute to
69+
/// every single syntax item that could have attributes applied to it.
70+
/// Your accept mappings should determine whether this returns something.
6271
fn finalize(self, cx: &FinalizeContext<'_>) -> Option<AttributeKind>;
6372
}
6473

0 commit comments

Comments
 (0)