@@ -448,6 +448,66 @@ fn main() {
448448The two ` 'x ` names did not clash, which would have caused the loop
449449to print "I am never printed" and to run forever.
450450
451+ # Scoping and macro import/export
452+
453+ Macros occupy a single global namespace. The interaction with Rust's system of
454+ modules and crates is somewhat complex.
455+
456+ Definition and expansion of macros both happen in a single depth-first,
457+ lexical-order traversal of a crate's source. So a macro defined at module scope
458+ is visible to any subsequent code in the same module, which includes the body
459+ of any subsequent child ` mod ` items.
460+
461+ If a module has the ` macro_escape ` attribute, its macros are also visible in
462+ its parent module after the child's ` mod ` item. If the parent also has
463+ ` macro_escape ` then the macros will be visible in the grandparent after the
464+ parent's ` mod ` item, and so forth.
465+
466+ Independent of ` macro_escape ` , the ` macro_export ` attribute controls visibility
467+ between crates. Any ` macro_rules! ` definition with the ` macro_export `
468+ attribute will be visible to other crates that have loaded this crate with
469+ ` phase(plugin) ` . There is currently no way for the importing crate to control
470+ which macros are imported.
471+
472+ An example:
473+
474+ ``` rust
475+ # #![feature(macro_rules)]
476+ macro_rules! m1 (() => (()))
477+
478+ // visible here: m1
479+
480+ mod foo {
481+ // visible here: m1
482+
483+ #[macro_export]
484+ macro_rules! m2 (() => (()))
485+
486+ // visible here: m1, m2
487+ }
488+
489+ // visible here: m1
490+
491+ macro_rules! m3 (() => (()))
492+
493+ // visible here: m1, m3
494+
495+ #[macro_escape]
496+ mod bar {
497+ // visible here: m1, m3
498+
499+ macro_rules! m4 (() => (()))
500+
501+ // visible here: m1, m3, m4
502+ }
503+
504+ // visible here: m1, m3, m4
505+ # fn main () { }
506+ ```
507+
508+ When this library is loaded with ` #[phase(plugin)] extern crate ` , only ` m2 `
509+ will be imported.
510+
451511# A final note
452512
453513Macros, as currently implemented, are not for the faint of heart. Even
0 commit comments