Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small macro cleanups #20776

Merged
merged 2 commits into from
Jan 10, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update macro scope intro
  • Loading branch information
Keegan McAllister committed Jan 9, 2015
commit a96a8b2b2526aaa631183f71aef9acf390b61f48
8 changes: 6 additions & 2 deletions src/doc/trpl/macros.md
Original file line number Diff line number Diff line change
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