]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/plugin/load.rs
rollup merge of #21830: japaric/for-cleanup
[rust.git] / src / librustc / plugin / load.rs
index ef8a89c40fb5ade2daba2b139355ece146001b22..dd0b0a63ced9de64a3b63eddf14ace3d25b26bc6 100644 (file)
@@ -15,7 +15,7 @@
 use plugin::registry::Registry;
 
 use std::mem;
-use std::os;
+use std::env;
 use std::dynamic_lib::DynamicLibrary;
 use std::collections::HashSet;
 use syntax::ast;
@@ -73,14 +73,16 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate,
     // We need to error on `#[macro_use] extern crate` when it isn't at the
     // crate root, because `$crate` won't work properly. Identify these by
     // spans, because the crate map isn't set up yet.
-    for vi in krate.module.view_items.iter() {
-        loader.span_whitelist.insert(vi.span);
+    for item in &krate.module.items {
+        if let ast::ItemExternCrate(_) = item.node {
+            loader.span_whitelist.insert(item.span);
+        }
     }
 
     visit::walk_crate(&mut loader, krate);
 
     if let Some(plugins) = addl_plugins {
-        for plugin in plugins.iter() {
+        for plugin in &plugins {
             loader.load_plugin(CrateOrString::Str(plugin.as_slice()),
                                                   None, None, None)
         }
@@ -91,18 +93,21 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate,
 
 // note that macros aren't expanded yet, and therefore macros can't add plugins.
 impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
-    fn visit_view_item(&mut self, vi: &ast::ViewItem) {
+    fn visit_item(&mut self, item: &ast::Item) {
         // We're only interested in `extern crate`.
-        match vi.node {
-            ast::ViewItemExternCrate(..) => (),
-            _ => return,
+        match item.node {
+            ast::ItemExternCrate(_) => {}
+            _ => {
+                visit::walk_item(self, item);
+                return;
+            }
         }
 
         // Parse the attributes relating to macro / plugin loading.
         let mut plugin_attr = None;
         let mut macro_selection = Some(HashSet::new());  // None => load all
         let mut reexport = HashSet::new();
-        for attr in vi.attrs.iter() {
+        for attr in &item.attrs {
             let mut used = true;
             match attr.name().get() {
                 "phase" => {
@@ -122,7 +127,7 @@ fn visit_view_item(&mut self, vi: &ast::ViewItem) {
                         macro_selection = None;
                     }
                     if let (Some(sel), Some(names)) = (macro_selection.as_mut(), names) {
-                        for name in names.iter() {
+                        for name in names {
                             if let ast::MetaWord(ref name) = name.node {
                                 sel.insert(name.clone());
                             } else {
@@ -140,7 +145,7 @@ fn visit_view_item(&mut self, vi: &ast::ViewItem) {
                         }
                     };
 
-                    for name in names.iter() {
+                    for name in names {
                         if let ast::MetaWord(ref name) = name.node {
                             reexport.insert(name.clone());
                         } else {
@@ -155,7 +160,10 @@ fn visit_view_item(&mut self, vi: &ast::ViewItem) {
             }
         }
 
-        self.load_plugin(CrateOrString::Krate(vi), plugin_attr, macro_selection, Some(reexport))
+        self.load_plugin(CrateOrString::Krate(item),
+                         plugin_attr,
+                         macro_selection,
+                         Some(reexport))
     }
 
     fn visit_mac(&mut self, _: &ast::Mac) {
@@ -196,7 +204,7 @@ pub fn load_plugin<'b>(&mut self,
             }
         }
 
-        for mut def in macros.into_iter() {
+        for mut def in macros {
             let name = token::get_ident(def.ident);
             def.use_locally = match macro_selection.as_ref() {
                 None => true,
@@ -225,7 +233,7 @@ fn dylink_registrar<'b>(&mut self,
                         path: Path,
                         symbol: String) -> PluginRegistrarFun {
         // Make sure the path contains a / or the linker will search for it.
-        let path = os::make_absolute(&path).unwrap();
+        let path = env::current_dir().unwrap().join(&path);
 
         let lib = match DynamicLibrary::open(Some(&path)) {
             Ok(lib) => lib,