about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-10-13 15:10:05 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-10-13 15:10:05 -0700
commit030c79c91a7661bf173561cd9ba211d5e64f2805 (patch)
tree3110d2e1998ca32fe6f759408c7dd33346b079e1
parentad25e560a03efa8ef81e559fc082aa9d9c1565bf (diff)
parent84d1cbfd25f26e32e8f1bae9d380cc585afe0668 (diff)
downloadrust-030c79c91a7661bf173561cd9ba211d5e64f2805.tar.gz
rust-030c79c91a7661bf173561cd9ba211d5e64f2805.zip
rollup merge of #17991 : sfackler/extern-error
-rw-r--r--src/librustc/metadata/loader.rs71
-rw-r--r--src/test/compile-fail/empty-extern-arg.rs14
2 files changed, 54 insertions, 31 deletions
diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs
index 62c179f598c..d6b02a1d063 100644
--- a/src/librustc/metadata/loader.rs
+++ b/src/librustc/metadata/loader.rs
@@ -1,4 +1,4 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -641,41 +641,50 @@ impl<'a> Context<'a> {
         // rlibs/dylibs.
         let sess = self.sess;
         let dylibname = self.dylibname();
-        let mut locs = locs.iter().map(|l| Path::new(l.as_slice())).filter(|loc| {
-            if !loc.exists() {
-                sess.err(format!("extern location does not exist: {}",
-                                 loc.display()).as_slice());
-                return false;
-            }
-            let file = loc.filename_str().unwrap();
-            if file.starts_with("lib") && file.ends_with(".rlib") {
-                return true
-            } else {
-                match dylibname {
-                    Some((prefix, suffix)) => {
-                        if file.starts_with(prefix) && file.ends_with(suffix) {
-                            return true
+        let mut rlibs = HashSet::new();
+        let mut dylibs = HashSet::new();
+        {
+            let mut locs = locs.iter().map(|l| Path::new(l.as_slice())).filter(|loc| {
+                if !loc.exists() {
+                    sess.err(format!("extern location for {} does not exist: {}",
+                                     self.crate_name, loc.display()).as_slice());
+                    return false;
+                }
+                let file = match loc.filename_str() {
+                    Some(file) => file,
+                    None => {
+                        sess.err(format!("extern location for {} is not a file: {}",
+                                         self.crate_name, loc.display()).as_slice());
+                        return false;
+                    }
+                };
+                if file.starts_with("lib") && file.ends_with(".rlib") {
+                    return true
+                } else {
+                    match dylibname {
+                        Some((prefix, suffix)) => {
+                            if file.starts_with(prefix) && file.ends_with(suffix) {
+                                return true
+                            }
                         }
+                        None => {}
                     }
-                    None => {}
                 }
-            }
-            sess.err(format!("extern location is of an unknown type: {}",
-                             loc.display()).as_slice());
-            false
-        });
+                sess.err(format!("extern location for {} is of an unknown type: {}",
+                                 self.crate_name, loc.display()).as_slice());
+                false
+            });
 
-        // Now that we have an iterator of good candidates, make sure there's at
-        // most one rlib and at most one dylib.
-        let mut rlibs = HashSet::new();
-        let mut dylibs = HashSet::new();
-        for loc in locs {
-            if loc.filename_str().unwrap().ends_with(".rlib") {
-                rlibs.insert(fs::realpath(&loc).unwrap());
-            } else {
-                dylibs.insert(fs::realpath(&loc).unwrap());
+            // Now that we have an iterator of good candidates, make sure there's at
+            // most one rlib and at most one dylib.
+            for loc in locs {
+                if loc.filename_str().unwrap().ends_with(".rlib") {
+                    rlibs.insert(fs::realpath(&loc).unwrap());
+                } else {
+                    dylibs.insert(fs::realpath(&loc).unwrap());
+                }
             }
-        }
+        };
 
         // Extract the rlib/dylib pair.
         let mut metadata = None;
diff --git a/src/test/compile-fail/empty-extern-arg.rs b/src/test/compile-fail/empty-extern-arg.rs
new file mode 100644
index 00000000000..9b7df81a5dc
--- /dev/null
+++ b/src/test/compile-fail/empty-extern-arg.rs
@@ -0,0 +1,14 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: --extern std=
+// error-pattern: is not a file
+
+fn main() {}