File tree 1 file changed +6
-2
lines changed
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -440,14 +440,18 @@ to print "I am never printed" and to run forever.
440
440
441
441
# Scoping and macro import/export
442
442
443
- Macros occupy a single global namespace. The interaction with Rust's system of
444
- modules and crates is somewhat complex.
443
+ Macros are expanded at an early stage in compilation, before name resolution.
444
+ One downside is that scoping works differently for macros, compared to other
445
+ constructs in the language.
445
446
446
447
Definition and expansion of macros both happen in a single depth-first,
447
448
lexical-order traversal of a crate's source. So a macro defined at module scope
448
449
is visible to any subsequent code in the same module, which includes the body
449
450
of any subsequent child ` mod ` items.
450
451
452
+ A macro defined within the body of a single ` fn ` , or anywhere else not at
453
+ module scope, is visible only within that item.
454
+
451
455
If a module has the ` macro_use ` attribute, its macros are also visible in its
452
456
parent module after the child's ` mod ` item. If the parent also has ` macro_use `
453
457
then the macros will be visible in the grandparent after the parent's ` mod `
You can’t perform that action at this time.
0 commit comments