diff options
| author | bors <bors@rust-lang.org> | 2014-07-12 11:06:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-07-12 11:06:39 +0000 |
| commit | cdd6346f458084ef9f9e6e1b640225be4a8aca70 (patch) | |
| tree | 92473d4a48cf9609db4295a4ea546916c38dfe99 /src/librustc/front | |
| parent | 767f4a7937c9f8a56cf4d1ac8fd111d481312f34 (diff) | |
| parent | c253b3675ab03b6c64021e8acee3988cea81f3f9 (diff) | |
auto merge of #15601 : jbclements/rust/disable-default-macro-behavior, r=alexcrichton
Our AST definition can include macro invocations, which can expand into all kinds of things. Macro invocations are expanded away during expansion time, and the rest of the compiler doesn't have to deal with them. However, we have no way of enforcing this. This patch adds two protective mechanisms. First, it adds a (quick) explicit check that ensures there are no macro invocations remaining in the AST after expansion. Second, it updates the visit and fold mechanisms so that by default, they will not traverse macro invocations. It's easy enough to add this, if desired (it's documented in the source, and examples appear, e.g. in the IdentFinder. Along the way, I also consulted with @sfackler to refactor the macro export mechanism so that it stores macro text spans in a side table, rather than leaving them in the AST.
Diffstat (limited to 'src/librustc/front')
| -rw-r--r-- | src/librustc/front/config.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/librustc/front/config.rs b/src/librustc/front/config.rs index 9bff6620aaa..0c39cf350a6 100644 --- a/src/librustc/front/config.rs +++ b/src/librustc/front/config.rs @@ -14,6 +14,8 @@ use syntax::codemap; use std::gc::{Gc, GC}; +/// A folder that strips out items that do not belong in the current +/// configuration. struct Context<'a> { in_cfg: |attrs: &[ast::Attribute]|: 'a -> bool, } @@ -41,6 +43,9 @@ impl<'a> fold::Folder for Context<'a> { fn fold_expr(&mut self, expr: Gc<ast::Expr>) -> Gc<ast::Expr> { fold_expr(self, expr) } + fn fold_mac(&mut self, mac: &ast::Mac) -> ast::Mac { + fold::fold_mac(mac, self) + } } pub fn strip_items(krate: ast::Crate, |
