You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/procedural-macros.md
+9-8Lines changed: 9 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -228,14 +228,15 @@ A helper attribute for a derive macro is declared by adding its identifier to th
228
228
> }
229
229
> ```
230
230
231
+
<!-- template:attributes -->
231
232
r[macro.proc.attribute]
232
233
## The `proc_macro_attribute` attribute
233
234
234
235
r[macro.proc.attribute.intro]
235
236
The *`proc_macro_attribute` [attribute][attributes]* defines an *attribute macro* which can be used as an [outer attribute][attributes].
236
237
237
238
> [!EXAMPLE]
238
-
> The following attribute macro takes the input stream and returns it asis, effectively being the no-op of attributes.
239
+
> This attribute macro takes the input stream and emits it as-is, effectively being a no-op attribute.
239
240
>
240
241
> <!-- ignore: test doesn't support proc-macro -->
241
242
> ```rust,ignore
@@ -250,7 +251,7 @@ The *`proc_macro_attribute` [attribute][attributes]* defines an *attribute macro
250
251
> ```
251
252
252
253
> [!EXAMPLE]
253
-
> This following example shows the stringified [`TokenStream`s] that the attribute macros see. The output will show in the output of the compiler. The output is shown in the comments after the function prefixed with "out:".
254
+
> This shows, in the output of the compiler, the stringified [`TokenStream`s] that attribute macros see.
254
255
>
255
256
> <!-- ignore: test doesn't support proc-macro -->
256
257
> ```rust,ignore
@@ -273,36 +274,36 @@ The *`proc_macro_attribute` [attribute][attributes]* defines an *attribute macro
273
274
>
274
275
> use my_macro::show_streams;
275
276
>
276
-
> // Example: Basic function
277
+
> // Example: Basic function.
277
278
> #[show_streams]
278
279
> fn invoke1() {}
279
280
> // out: attr: ""
280
281
> // out: item: "fn invoke1() {}"
281
282
>
282
-
> // Example: Attribute with input
283
+
> // Example: Attribute with input.
283
284
> #[show_streams(bar)]
284
285
> fn invoke2() {}
285
286
> // out: attr: "bar"
286
287
> // out: item: "fn invoke2() {}"
287
288
>
288
-
> // Example: Multiple tokens in the input
289
+
> // Example: Multiple tokens in the input.
289
290
> #[show_streams(multiple => tokens)]
290
291
> fn invoke3() {}
291
292
> // out: attr: "multiple => tokens"
292
293
> // out: item: "fn invoke3() {}"
293
294
>
294
-
> // Example:
295
+
> // Example: Delimiters in the input.
295
296
> #[show_streams { delimiters }]
296
297
> fn invoke4() {}
297
298
> // out: attr: "delimiters"
298
299
> // out: item: "fn invoke4() {}"
299
300
> ```
300
301
301
302
r[macro.proc.attribute.syntax]
302
-
The `proc_macro_attribute` attribute uses the [MetaWord] syntax and thus does not take any inputs.
303
+
The `proc_macro_attribute` attribute uses the [MetaWord] syntax.
303
304
304
305
r[macro.proc.attribute.allowed-positions]
305
-
The `proc_macro_attribute` attribute may only be applied to a function with the signature of `pub fn(TokenStream, TokenStream) -> TokenStream` where [`TokenStream`] comes from the [`proc_macro` crate]. It must have the ["Rust" ABI][items.fn.extern]. No other function qualifiers are allowed.
306
+
The `proc_macro_attribute` attribute may only be applied to a `pub` function of type `fn(TokenStream, TokenStream) -> TokenStream` where [`TokenStream`] comes from the [`proc_macro` crate]. It must have the ["Rust" ABI][items.fn.extern]. No other function qualifiers are allowed. It must be located in the root of the crate.
306
307
307
308
r[macro.proc.attribute.duplicates]
308
309
The `proc_macro_attribute` attribute may only be specified once on a function.
0 commit comments