Skip to content

Commit dd41f1f

Browse files
committed
Revise proc_macro_attribute text
1 parent fe72d24 commit dd41f1f

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/procedural-macros.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,15 @@ A helper attribute for a derive macro is declared by adding its identifier to th
240240
> }
241241
> ```
242242
243+
<!-- template:attributes -->
243244
r[macro.proc.attribute]
244245
## The `proc_macro_attribute` attribute
245246
246247
r[macro.proc.attribute.intro]
247248
The *`proc_macro_attribute` [attribute][attributes]* defines an *attribute macro* which can be used as an [outer attribute][attributes].
248249
249250
> [!EXAMPLE]
250-
> The following attribute macro takes the input stream and returns it as is, effectively being the no-op of attributes.
251+
> This attribute macro takes the input stream and emits it as-is, effectively being a no-op attribute.
251252
>
252253
> <!-- ignore: test doesn't support proc-macro -->
253254
> ```rust,ignore
@@ -262,14 +263,13 @@ The *`proc_macro_attribute` [attribute][attributes]* defines an *attribute macro
262263
> ```
263264
264265
> [!EXAMPLE]
265-
> 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:".
266+
> This shows, in the output of the compiler, the stringified [`TokenStream`s] that attribute macros see.
266267
>
267268
> <!-- ignore: test doesn't support proc-macro -->
268269
> ```rust,ignore
269270
> // my-macro/src/lib.rs
270271
> # extern crate proc_macro;
271272
> # use proc_macro::TokenStream;
272-
>
273273
> #[proc_macro_attribute]
274274
> pub fn show_streams(attr: TokenStream, item: TokenStream) -> TokenStream {
275275
> println!("attr: \"{attr}\"");
@@ -285,36 +285,36 @@ The *`proc_macro_attribute` [attribute][attributes]* defines an *attribute macro
285285
>
286286
> use my_macro::show_streams;
287287
>
288-
> // Example: Basic function
288+
> // Example: Basic function.
289289
> #[show_streams]
290290
> fn invoke1() {}
291291
> // out: attr: ""
292292
> // out: item: "fn invoke1() {}"
293293
>
294-
> // Example: Attribute with input
294+
> // Example: Attribute with input.
295295
> #[show_streams(bar)]
296296
> fn invoke2() {}
297297
> // out: attr: "bar"
298298
> // out: item: "fn invoke2() {}"
299299
>
300-
> // Example: Multiple tokens in the input
300+
> // Example: Multiple tokens in the input.
301301
> #[show_streams(multiple => tokens)]
302302
> fn invoke3() {}
303303
> // out: attr: "multiple => tokens"
304304
> // out: item: "fn invoke3() {}"
305305
>
306-
> // Example:
306+
> // Example: Delimiters in the input.
307307
> #[show_streams { delimiters }]
308308
> fn invoke4() {}
309309
> // out: attr: "delimiters"
310310
> // out: item: "fn invoke4() {}"
311311
> ```
312312
313313
r[macro.proc.attribute.syntax]
314-
The `proc_macro_attribute` attribute uses the [MetaWord] syntax and thus does not take any inputs.
314+
The `proc_macro_attribute` attribute uses the [MetaWord] syntax.
315315
316316
r[macro.proc.attribute.allowed-positions]
317-
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.
317+
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.
318318
319319
r[macro.proc.attribute.duplicates]
320320
The `proc_macro_attribute` attribute may only be specified once on a function.
@@ -325,17 +325,17 @@ The `proc_macro_attribute` attribute defines the attribute in the [macro namespa
325325
r[macro.proc.attribute.use-positions]
326326
Attribute macros can only be used on:
327327
328-
- [items]
329-
- items in [`extern` blocks]
330-
- inherent and trait [implementations]
331-
- [trait definitions]
328+
- [Items]
329+
- Items in [`extern` blocks]
330+
- Inherent and trait [implementations]
331+
- [Trait definitions]
332332
333333
r[macro.proc.attribute.behavior]
334-
The first [`TokenStream`] parameter is the delimited token tree following the attribute's name, not including the outer delimiters. If the attribute is written as a bare attribute name, the [`TokenStream`] is empty.
334+
The first [`TokenStream`] parameter is the delimited token tree following the attribute's name but not including the outer delimiters. If the applied attribute contains only the attribute name or the attribute name followed by empty delimiters, the [`TokenStream`] is empty.
335335
336-
The second [`TokenStream`] is the rest of the [item] including other [attributes] on the [item].
336+
The second [`TokenStream`] is the rest of the [item], including other [attributes] on the [item].
337337
338-
The returned [`TokenStream`] replaces the [item] with an arbitrary number of [items].
338+
The item to which the attribute is applied is replaced by the zero or more items in the returned [`TokenStream`].
339339
340340
r[macro.proc.token]
341341
## Declarative macro tokens and procedural macro tokens

0 commit comments

Comments
 (0)