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
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
+
> modinner {
340
+
> macro_rules!m {
341
+
> () => {};
342
+
> }
343
+
> }
344
+
> m!();
345
+
> ```
346
+
>
347
+
> ```rust,ignore
348
+
> #[macro_use]
349
+
> externcrate log;
350
+
> ```
335
351
336
352
r[macro.decl.scope.macro_use.syntax]
337
-
When used on a module, the `macro_use` attribute uses the [MetaWord] syntax.
353
+
Whenusedonmodules, the `macro_use` attributeusesthe [MetaWord] syntax.
338
354
339
-
When used on an `extern crate`, it uses either the [MetaWord]or[MetaListIdents]syntax (described in [macro.decl.scope.macro_use.prelude]).
355
+
Whenusedon `externcrate`, it uses the [MetaWord] and [MetaListIdents] syntaxes. For more on how these syntaxes may be used, see [macro.decl.scope.macro_use.prelude].
340
356
341
357
r[macro.decl.scope.macro_use.allowed-positions]
342
358
The `macro_use` attribute may be applied to modules or `externcrate`.
@@ -350,13 +366,13 @@ The `macro_use` attribute may not be used on [`extern crate self`].
350
366
r[macro.decl.scope.macro_use.duplicates]
351
367
The `macro_use` attribute may be used any number of times on a form.
352
368
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.
354
370
355
371
> [!NOTE]
356
-
> `rustc`warns about duplicate [MetaWord]`macro_use` attributes.
372
+
> `rustc` lints against duplicate [MetaWord] `macro_use` attributes.
357
373
358
374
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.
375
+
When `macro_use` is used on a module, the module's macro scope extends beyond the module's lexical scope.
360
376
361
377
> [!EXAMPLE]
362
378
> ```rust
@@ -366,8 +382,7 @@ When `macro_use` is used on a module, it causes the module's macro scope to not
366
382
> () => {};
367
383
> }
368
384
> }
369
-
>
370
-
> m!();
385
+
> m!(); // OK
371
386
> ```
372
387
373
388
r[macro.decl.scope.macro_use.prelude]
@@ -380,11 +395,11 @@ When using the [MetaWord] syntax, all exported macros are imported. When using t
380
395
> [!EXAMPLE]
381
396
> <!-- ignore: requires external crates -->
382
397
> ```rust,ignore
383
-
> #[macro_use(lazy_static)] // Or #[macro_use] to import all macros.
398
+
> #[macro_use(lazy_static)] // Or `#[macro_use]` to import all macros.
384
399
> externcrate lazy_static;
385
400
>
386
401
> lazy_static!{}
387
-
> // self::lazy_static!{} // Error: lazy_static is not defined in `self`
402
+
> // self::lazy_static!{} // ERROR: lazy_static is not defined in `self`.
0 commit comments