]> git.lizzy.rs Git - rust.git/commitdiff
Update macro scope intro
authorKeegan McAllister <kmcallister@mozilla.com>
Thu, 8 Jan 2015 19:56:10 +0000 (11:56 -0800)
committerKeegan McAllister <kmcallister@mozilla.com>
Fri, 9 Jan 2015 19:06:17 +0000 (11:06 -0800)
src/doc/trpl/macros.md

index c694806b4bab9f60203f0c485da1160bf611399d..9b9af2c65cad5773fa2b98ed4a34f18865409a7c 100644 (file)
@@ -440,14 +440,18 @@ to print "I am never printed" and to run forever.
 
 # Scoping and macro import/export
 
-Macros occupy a single global namespace. The interaction with Rust's system of
-modules and crates is somewhat complex.
+Macros are expanded at an early stage in compilation, before name resolution.
+One downside is that scoping works differently for macros, compared to other
+constructs in the language.
 
 Definition and expansion of macros both happen in a single depth-first,
 lexical-order traversal of a crate's source. So a macro defined at module scope
 is visible to any subsequent code in the same module, which includes the body
 of any subsequent child `mod` items.
 
+A macro defined within the body of a single `fn`, or anywhere else not at
+module scope, is visible only within that item.
+
 If a module has the `macro_use` attribute, its macros are also visible in its
 parent module after the child's `mod` item. If the parent also has `macro_use`
 then the macros will be visible in the grandparent after the parent's `mod`