1313>
1414> _ AttrInput_ :\
1515>   ;  ;   ;  ; [ _ DelimTokenTree_ ] \
16- >   ;  ; | ` = ` [ _ LiteralExpression _ ] < sub > _ without suffix _ </ sub >
16+ >   ;  ; | ` = ` [ _ Expression _ ]
1717
1818An _ attribute_ is a general, free-form metadatum that is interpreted according
1919to name, convention, language, and compiler version. Attributes are modeled
@@ -26,7 +26,7 @@ the bang after the hash, apply to the thing that follows the attribute.
2626The attribute consists of a path to the attribute, followed by an optional
2727delimited token tree whose interpretation is defined by the attribute.
2828Attributes other than macro attributes also allow the input to be an equals
29- sign (` = ` ) followed by a literal expression. See the [ meta item
29+ sign (` = ` ) followed by a expression. See the [ meta item
3030syntax] ( #meta-item-attribute-syntax ) below for more details.
3131
3232Attributes can be classified into the following kinds:
@@ -94,18 +94,42 @@ attributes]. It has the following grammar:
9494> ** <sup >Syntax</sup >** \
9595> _ MetaItem_ :\
9696>   ;  ;   ;  ; [ _ SimplePath_ ] \
97- >   ;  ; | [ _ SimplePath_ ] ` = ` [ _ LiteralExpression _ ] < sub > _ without suffix _ </ sub > \
97+ >   ;  ; | [ _ SimplePath_ ] ` = ` [ _ Expression _ ] \
9898>   ;  ; | [ _ SimplePath_ ] ` ( ` _ MetaSeq_ <sup >?</sup > ` ) `
9999>
100100> _ MetaSeq_ :\
101101>   ;  ; _ MetaItemInner_ ( ` , ` MetaItemInner )<sup >\* </sup > ` , ` <sup >?</sup >
102102>
103103> _ MetaItemInner_ :\
104104>   ;  ;   ;  ; _ MetaItem_ \
105- >   ;  ; | [ _ LiteralExpression_ ] <sub >_ without suffix_ </sub >
105+ >   ;  ; | [ _ Expression_ ]
106+
107+ Expressions in meta items must macro-expand to literal expressions, which must not
108+ include integer or float type suffixes. Expressions which are not literal expressions
109+ will be syntactically accepted (and can be passed to proc-macros), but will be rejected after parsing.
110+
111+ Note that if the attribute appears within another macro, it will be expanded
112+ after that outer macro. For example, the following code will expand the
113+ ` Serialize ` proc-macro first, which must preserve the ` include_str! ` call in
114+ order for it to be expanded:
115+
116+ ``` rust ignore
117+ #[derive(Serialize )]
118+ struct Foo {
119+ #[doc = include_str! (" x.md" )]
120+ x : u32
121+ }
122+ ```
106123
107- Literal expressions in meta items must not include integer or float type
108- suffixes.
124+ Additionally, macros in attributes will be expanded only after all other attributes applied to the item:
125+
126+ ``` rust ignore
127+ #[macro_attr1] // expanded first
128+ #[doc = mac! ()] // `mac!` is expanded fourth.
129+ #[macro_attr2] // expanded second
130+ #[derive(MacroDerive1 , MacroDerive2 )] // expanded third
131+ fn foo () {}
132+ ```
109133
110134Various built-in attributes use different subsets of the meta item syntax to
111135specify their inputs. The following grammar rules show some commonly used
0 commit comments