about summary refs log tree commit diff
path: root/src/librustc/plugin
diff options
context:
space:
mode:
authorJohn Clements <clements@racket-lang.org>2014-07-09 14:48:12 -0700
committerJohn Clements <clements@racket-lang.org>2014-07-11 10:32:41 -0700
commit53642eed801d157613de0998cdcf0a3da8c36cb3 (patch)
tree4d9232bac52072c177895e7de997b5ca00da98d5 /src/librustc/plugin
parentf1ad425199b0d89dab275a8c8f6f29a73d316f70 (diff)
downloadrust-53642eed801d157613de0998cdcf0a3da8c36cb3.tar.gz
rust-53642eed801d157613de0998cdcf0a3da8c36cb3.zip
make walk/visit_mac opt-in only
macros can expand into arbitrary items, exprs, etc. This
means that using a default walker or folder on an AST before
macro expansion is complete will miss things (the things that
the macros expand into). As a partial fence against this, this
commit moves the default traversal of macros into a separate
procedure, and makes the default trait implementation signal
an error. This means that Folders and Visitors can traverse
macros if they want to, but they need to explicitly add an
impl that calls the walk_mac or fold_mac procedure

This should prevent problems down the road.
Diffstat (limited to 'src/librustc/plugin')
-rw-r--r--src/librustc/plugin/load.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/librustc/plugin/load.rs b/src/librustc/plugin/load.rs
index 79d0690653f..499cffa42aa 100644
--- a/src/librustc/plugin/load.rs
+++ b/src/librustc/plugin/load.rs
@@ -72,6 +72,7 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate) -> Plugins {
     loader.plugins
 }
 
+// note that macros aren't expanded yet, and therefore macros can't add plugins.
 impl<'a> Visitor<()> for PluginLoader<'a> {
     fn visit_view_item(&mut self, vi: &ast::ViewItem, _: ()) {
         match vi.node {
@@ -109,6 +110,10 @@ impl<'a> Visitor<()> for PluginLoader<'a> {
             _ => (),
         }
     }
+    fn visit_mac(&mut self, _: &ast::Mac, _:()) {
+        // bummer... can't see plugins inside macros.
+        // do nothing.
+    }
 }
 
 impl<'a> PluginLoader<'a> {