Skip to content

Commit 0cb4d69

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 135377 b: refs/heads/snap-stage3 c: 4ced7a9 h: refs/heads/master i: 135375: 8928d0f v: v3
1 parent 2dd413a commit 0cb4d69

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 74090504219e4e37c1a6d9fdd8600f44b51c7b04
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: c8bdba77fca16ebf5ad6c63a37a8dd8fd2afda8e
4+
refs/heads/snap-stage3: 4ced7a9637c10196883733fa81ac67d02269a76e
55
refs/heads/try: 14378ea357c06c23607ca61ade44f60a7a64a1c7
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/doc/guide-macros.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,66 @@ fn main() {
448448
The two `'x` names did not clash, which would have caused the loop
449449
to 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

453513
Macros, as currently implemented, are not for the faint of heart. Even

0 commit comments

Comments
 (0)