Skip to content

Commit 461e20b

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 135749 b: refs/heads/auto c: 4ced7a9 h: refs/heads/master i: 135747: d01c151 v: v3
1 parent 8b53359 commit 461e20b

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
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: c8bdba77fca16ebf5ad6c63a37a8dd8fd2afda8e
16+
refs/heads/auto: 4ced7a9637c10196883733fa81ac67d02269a76e
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/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)