Skip to content

Commit 4647e87

Browse files
traviscrossehuss
authored andcommitted
Revise macro_use text
1 parent dca9117 commit 4647e87

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/macros-by-example.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,28 @@ r[macro.decl.scope.macro_use]
331331
### The `macro_use` attribute
332332

333333
r[macro.decl.scope.macro_use.intro]
334-
The *`macro_use` [attribute][attributes]* has two purposes. It may be used on modules to extend the scope of macros defined within them, and it may be used on [`extern crate`][items.extern-crate] to import macros from another crate.
334+
The *`macro_use` [attribute][attributes]* has two purposes: it may be used on modules to extend the scope of macros defined within them, and it may be used on [`extern crate`][items.extern-crate] to import macros from another crate into the [`macro_use` prelude].
335+
336+
> [!EXAMPLE]
337+
> ```rust
338+
> #[macro_use]
339+
> mod inner {
340+
> macro_rules! m {
341+
> () => {};
342+
> }
343+
> }
344+
> m!();
345+
> ```
346+
>
347+
> ```rust,ignore
348+
> #[macro_use]
349+
> extern crate log;
350+
> ```
335351
336352
r[macro.decl.scope.macro_use.syntax]
337-
When used on a module, the `macro_use` attribute uses the [MetaWord] syntax.
353+
When used on modules, the `macro_use` attribute uses the [MetaWord] syntax.
338354
339-
When used on an `extern crate`, it uses either the [MetaWord] or [MetaListIdents] syntax (described in [macro.decl.scope.macro_use.prelude]).
355+
When used on `extern crate`, it uses the [MetaWord] and [MetaListIdents] syntaxes. For more on how these syntaxes may be used, see [macro.decl.scope.macro_use.prelude].
340356
341357
r[macro.decl.scope.macro_use.allowed-positions]
342358
The `macro_use` attribute may be applied to modules or `extern crate`.
@@ -350,13 +366,15 @@ The `macro_use` attribute may not be used on [`extern crate self`].
350366
r[macro.decl.scope.macro_use.duplicates]
351367
The `macro_use` attribute may be used any number of times on a form.
352368
353-
Multiple instances of `macro_use` that are in the [MetaListIdents] syntax may be specified. The union of all specified macros to import will be imported.
369+
Multiple instances of `macro_use` in the [MetaListIdents] syntax may be specified. The union of all specified macros will be imported.
354370
355371
> [!NOTE]
356-
> `rustc` warns about duplicate [MetaWord] `macro_use` attributes.
372+
> On modules, `rustc` lints against any [MetaWord] `macro_use` attributes following the first.
373+
>
374+
> On `extern crate`, `rustc` lints against any `macro_use` attributes that have no effect due to not importing any macros not already imported by another `macro_use` attribute. If two or more [MetaListIdents] `macro_use` attributes import the same macro, the first is linted against. If any [MetaWord] `macro_use` attributes are present, all [MetaListIdents] `macro_use` attributes are linted against. If two or more [MetaWord] `macro_use` attributes are present, the ones following the first are linted against.
357375
358376
r[macro.decl.scope.macro_use.mod-decl]
359-
When `macro_use` is used on a module, it causes the module's macro scope to not end when the module is closed.
377+
When `macro_use` is used on a module, the module's macro scope extends beyond the module's lexical scope.
360378
361379
> [!EXAMPLE]
362380
> ```rust
@@ -366,8 +384,7 @@ When `macro_use` is used on a module, it causes the module's macro scope to not
366384
> () => {};
367385
> }
368386
> }
369-
>
370-
> m!();
387+
> m!(); // OK
371388
> ```
372389
373390
r[macro.decl.scope.macro_use.prelude]
@@ -380,11 +397,11 @@ When using the [MetaWord] syntax, all exported macros are imported. When using t
380397
> [!EXAMPLE]
381398
> <!-- ignore: requires external crates -->
382399
> ```rust,ignore
383-
> #[macro_use(lazy_static)] // Or #[macro_use] to import all macros.
400+
> #[macro_use(lazy_static)] // Or `#[macro_use]` to import all macros.
384401
> extern crate lazy_static;
385402
>
386403
> lazy_static!{}
387-
> // self::lazy_static!{} // Error: lazy_static is not defined in `self`
404+
> // self::lazy_static!{} // ERROR: lazy_static is not defined in `self`.
388405
> ```
389406
390407
r[macro.decl.scope.macro_use.export]

0 commit comments

Comments
 (0)