@@ -75,9 +75,7 @@ the macro invocation operator (`!`).
75
75
These macros are defined by a [public] [function] with the `proc_macro`
76
76
[attribute ] and a signature of `(TokenStream) -> TokenStream`. The input
77
77
[`TokenStream` ] is what is inside the delimiters of the macro invocation and the
78
- output [`TokenStream`] replaces the entire macro invocation. It may contain an
79
- arbitrary number of [items]. These macros cannot expand to syntax that defines
80
- new `macro_rules` style macros.
78
+ output [`TokenStream`] replaces the entire macro invocation.
81
79
82
80
For example, the following macro definition ignores its input and outputs a
83
81
function `answer` into its scope.
@@ -105,11 +103,12 @@ fn main() {
105
103
}
106
104
```
107
105
108
- These macros are only invokable in [ modules] . They cannot even be invoked to
109
- create [ item declaration statements] . Furthermore, they must either be invoked
110
- with curly braces and no semicolon or a different delimiter followed by a
111
- semicolon. For example, ` make_answer ` from the previous example can be invoked
112
- as ` make_answer!{} ` , ` make_answer!(); ` or ` make_answer![]; ` .
106
+ Function-like procedural macros may expand to a [ type] or any number of
107
+ [ items] . They may be invoked in a [ type expression] , [ item] position (except
108
+ as a [ statement] ), including items in [ ` extern ` blocks] , inherent and trait
109
+ [ implementations] , and [ trait definitions] . They cannot be used in a
110
+ [ statement] , [ expression] , or [ pattern] . These macros cannot expand to syntax
111
+ that defines new [ ` macro_rules ` ] style macros.
113
112
114
113
### Derive macros
115
114
@@ -192,7 +191,9 @@ struct Struct {
192
191
193
192
### Attribute macros
194
193
195
- * Attribute macros* define new [ attributes] which can be attached to [ items] .
194
+ * Attribute macros* define new [ outer attributes] [ attributes ] which can be
195
+ attached to [ items] , including items in [ ` extern ` blocks] , inherent and trait
196
+ [ implementations] , and [ trait definitions] .
196
197
197
198
Attribute macros are defined by a [ public]   ; [ function] with the
198
199
` proc_macro_attribute ` [ attribute] that has a signature of `(TokenStream,
@@ -202,7 +203,7 @@ the attribute is written as a bare attribute name, the attribute
202
203
[ ` TokenStream ` ] is empty. The second [ ` TokenStream ` ] is the rest of the [ item]
203
204
including other [ attributes] on the [ item] . The returned [ ` TokenStream ` ]
204
205
replaces the [ item] with an arbitrary number of [ items] . These macros cannot
205
- expand to syntax that defines new ` macro_rules ` style macros.
206
+ expand to syntax that defines new [ ` macro_rules ` ] style macros.
206
207
207
208
For example, this attribute macro takes the input stream and returns it as is,
208
209
effectively being the no-op of attributes.
@@ -266,28 +267,35 @@ fn invoke4() {}
266
267
// out: item: "fn invoke4() {}"
267
268
```
268
269
270
+ [ Attribute macros ] : #attribute-macros
271
+ [ Cargo's build scripts ] : ../cargo/reference/build-scripts.html
272
+ [ Derive macros ] : #derive-macros
273
+ [ Function-like macros ] : #function-like-procedural-macros
269
274
[ `TokenStream` ] : ../proc_macro/struct.TokenStream.html
270
275
[ `TokenStream`s ] : ../proc_macro/struct.TokenStream.html
271
276
[ `compile_error` ] : ../std/macro.compile_error.html
272
277
[ `derive` attribute ] : attributes/derive.md
278
+ [ `extern` blocks ] : items/external-blocks.md
279
+ [ `macro_rules` ] : macros-by-example.md
273
280
[ `proc_macro` crate ] : ../proc_macro/index.html
274
- [ Cargo's build scripts ] : ../cargo/reference/build-scripts.html
275
- [ Derive macros ] : #derive-macros
276
- [ Attribute macros ] : #attribute-macros
277
- [ Function-like macros ] : #function-like-procedural-macros
278
281
[ attribute ] : attributes.md
279
282
[ attributes ] : attributes.md
280
283
[ block ] : expressions/block-expr.md
281
284
[ crate type ] : linkage.md
282
285
[ derive macro helper attributes ] : #derive-macro-helper-attributes
283
286
[ enum ] : items/enumerations.md
287
+ [ expression ] : expressions.md
288
+ [ function ] : items/functions.md
289
+ [ implementations ] : items/implementations.md
284
290
[ inert ] : attributes.md#active-and-inert-attributes
285
291
[ item ] : items.md
286
- [ item declaration statements ] : statements.md#item-declarations
287
292
[ items ] : items.md
288
- [ function ] : items/functions.md
289
293
[ module ] : items/modules.md
290
- [ modules ] : items/modules .md
294
+ [ pattern ] : patterns .md
291
295
[ public ] : visibility-and-privacy.md
296
+ [ statement ] : statements.md
292
297
[ struct ] : items/structs.md
298
+ [ trait definitions ] : items/traits.md
299
+ [ type expression ] : types.md#type-expressions
300
+ [ type ] : types.md
293
301
[ union ] : items/unions.md
0 commit comments