Skip to content

Commit

Permalink
Update macro scope intro
Browse files Browse the repository at this point in the history
  • Loading branch information
Keegan McAllister committed Jan 9, 2015
1 parent 128e7ff commit a96a8b2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/doc/trpl/macros.md
Expand Up @@ -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`
Expand Down

7 comments on commit a96a8b2

@bors
Copy link
Contributor

@bors bors commented on a96a8b2 Jan 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at kmcallister@a96a8b2

@bors
Copy link
Contributor

@bors bors commented on a96a8b2 Jan 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging kmcallister/rust/macro-cleanup = a96a8b2 into auto

@bors
Copy link
Contributor

@bors bors commented on a96a8b2 Jan 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status: {"merge_sha": "c133b2110b79d7a735032e4af431ee3a1143f3ce"}

@bors
Copy link
Contributor

@bors bors commented on a96a8b2 Jan 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kmcallister/rust/macro-cleanup = a96a8b2 merged ok, testing candidate = c133b21

@bors
Copy link
Contributor

@bors bors commented on a96a8b2 Jan 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c133b21

@bors
Copy link
Contributor

@bors bors commented on a96a8b2 Jan 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c133b21

Please sign in to comment.