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/macros-by-example.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -326,28 +326,29 @@ fn foo() {
326
326
// m!(); // Error: m is not in scope.
327
327
```
328
328
329
+
<!-- template:attributes -->
329
330
r[macro.decl.scope.macro_use]
330
331
### The `macro_use` attribute
331
332
332
333
r[macro.decl.scope.macro_use.intro]
333
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
335
335
336
r[macro.decl.scope.macro_use.syntax]
336
-
When used on a module, the `macro_use` attribute uses the [MetaWord] syntax and thus does not take any inputs.
337
+
When used on a module, the `macro_use` attribute uses the [MetaWord] syntax.
337
338
338
-
When used on an `extern crate`, it uses either the [MetaWord] or [MetaListIdents] syntax.
339
+
When used on an `extern crate`, it uses either the [MetaWord] or [MetaListIdents] syntax (described in [macro.decl.scope.macro_use.prelude]).
339
340
340
341
r[macro.decl.scope.macro_use.allowed-positions]
341
342
The `macro_use` attribute may be applied to modules or `extern crate`.
342
343
343
344
> [!NOTE]
344
-
> `rustc`currently warns in other positions, but this may be rejected in the future.
345
+
> `rustc`ignores use in other positions but lints against it. This may become an error in the future.
345
346
346
347
r[macro.decl.scope.macro_use.extern-crate-self]
347
348
The `macro_use` attribute may not be used on [`extern crate self`].
348
349
349
350
r[macro.decl.scope.macro_use.duplicates]
350
-
Duplicate instances of `macro_use`that are in the [MetaWord] syntax have no effect if there is already a `macro_use` with the [MetaWord] syntax.
351
+
The `macro_use`attribute may be used any number of times on a form.
351
352
352
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.
353
354
@@ -370,7 +371,7 @@ When `macro_use` is used on a module, it causes the module's macro scope to not
370
371
> ```
371
372
372
373
r[macro.decl.scope.macro_use.prelude]
373
-
When `macro_use` isusedonan `externcrate` declaration in the crate root, it imports exported macros from that crate.
374
+
Specifying `macro_use` onan `externcrate` declaration in the crate root imports exported macros from that crate.
374
375
375
376
Macros imported this way are imported into the [`macro_use` prelude], not textually, which means that they can be shadowed by any other name. While macros imported by `macro_use` can be used before the import statement, in case of a conflict, the last macro imported wins.
0 commit comments