about summary refs log tree commit diff
path: root/src/librustc/plugin
diff options
context:
space:
mode:
authorKeegan McAllister <kmcallister@mozilla.com>2015-01-02 12:50:45 -0800
committerKeegan McAllister <kmcallister@mozilla.com>2015-01-05 18:21:13 -0800
commitaa69cbde8279cd90457454c3b3f40a36e8a79dff (patch)
tree6fadc77e821fb42ff743b355a5432180848e1a30 /src/librustc/plugin
parent0816255c80ee3f2a8870ee5e4379e3739d8ed72e (diff)
downloadrust-aa69cbde8279cd90457454c3b3f40a36e8a79dff.tar.gz
rust-aa69cbde8279cd90457454c3b3f40a36e8a79dff.zip
Allow selective macro import
Diffstat (limited to 'src/librustc/plugin')
-rw-r--r--src/librustc/plugin/load.rs33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/librustc/plugin/load.rs b/src/librustc/plugin/load.rs
index 93c97f6caa6..3a9083828fc 100644
--- a/src/librustc/plugin/load.rs
+++ b/src/librustc/plugin/load.rs
@@ -87,8 +87,8 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
         }
 
         // Parse the attributes relating to macro / plugin loading.
-        let mut load_macros = false;
         let mut load_registrar = false;
+        let mut macro_selection = Some(HashSet::new());  // None => load all
         let mut reexport = HashSet::new();
         for attr in vi.attrs.iter() {
             let mut used = true;
@@ -98,7 +98,22 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
                                        #[macro_use], #[plugin], and/or #[no_link]");
                 }
                 "plugin" => load_registrar = true,
-                "macro_use" => load_macros = true,
+                "macro_use" => {
+                    let names = attr.meta_item_list();
+                    if names.is_none() {
+                        // no names => load all
+                        macro_selection = None;
+                    }
+                    if let (Some(sel), Some(names)) = (macro_selection.as_mut(), names) {
+                        for name in names.iter() {
+                            if let ast::MetaWord(ref name) = name.node {
+                                sel.insert(name.clone());
+                            } else {
+                                self.sess.span_err(name.span, "bad macro import");
+                            }
+                        }
+                    }
+                }
                 "macro_reexport" => {
                     let names = match attr.meta_item_list() {
                         Some(names) => names,
@@ -126,6 +141,11 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
         let mut macros = vec![];
         let mut registrar = None;
 
+        let load_macros = match macro_selection.as_ref() {
+            Some(sel) => sel.len() != 0 || reexport.len() != 0,
+            None => true,
+        };
+
         if load_macros || load_registrar {
             let pmd = self.reader.read_plugin_metadata(vi);
             if load_macros {
@@ -137,9 +157,12 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
         }
 
         for mut def in macros.into_iter() {
-            if reexport.contains(&token::get_ident(def.ident)) {
-                def.export = true;
-            }
+            let name = token::get_ident(def.ident);
+            def.use_locally = match macro_selection.as_ref() {
+                None => true,
+                Some(sel) => sel.contains(&name),
+            };
+            def.export = reexport.contains(&name);
             self.plugins.macros.push(def);
         }