Skip to content

Commit 84d1cbf

Browse files
committed
Don't ICE on bad extern paths
Closes #17990
1 parent ff61b74 commit 84d1cbf

File tree

2 files changed

+54
-31
lines changed

2 files changed

+54
-31
lines changed

src/librustc/metadata/loader.rs

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -641,41 +641,50 @@ impl<'a> Context<'a> {
641641
// rlibs/dylibs.
642642
let sess = self.sess;
643643
let dylibname = self.dylibname();
644-
let mut locs = locs.iter().map(|l| Path::new(l.as_slice())).filter(|loc| {
645-
if !loc.exists() {
646-
sess.err(format!("extern location does not exist: {}",
647-
loc.display()).as_slice());
648-
return false;
649-
}
650-
let file = loc.filename_str().unwrap();
651-
if file.starts_with("lib") && file.ends_with(".rlib") {
652-
return true
653-
} else {
654-
match dylibname {
655-
Some((prefix, suffix)) => {
656-
if file.starts_with(prefix) && file.ends_with(suffix) {
657-
return true
644+
let mut rlibs = HashSet::new();
645+
let mut dylibs = HashSet::new();
646+
{
647+
let mut locs = locs.iter().map(|l| Path::new(l.as_slice())).filter(|loc| {
648+
if !loc.exists() {
649+
sess.err(format!("extern location for {} does not exist: {}",
650+
self.crate_name, loc.display()).as_slice());
651+
return false;
652+
}
653+
let file = match loc.filename_str() {
654+
Some(file) => file,
655+
None => {
656+
sess.err(format!("extern location for {} is not a file: {}",
657+
self.crate_name, loc.display()).as_slice());
658+
return false;
659+
}
660+
};
661+
if file.starts_with("lib") && file.ends_with(".rlib") {
662+
return true
663+
} else {
664+
match dylibname {
665+
Some((prefix, suffix)) => {
666+
if file.starts_with(prefix) && file.ends_with(suffix) {
667+
return true
668+
}
658669
}
670+
None => {}
659671
}
660-
None => {}
661672
}
662-
}
663-
sess.err(format!("extern location is of an unknown type: {}",
664-
loc.display()).as_slice());
665-
false
666-
});
673+
sess.err(format!("extern location for {} is of an unknown type: {}",
674+
self.crate_name, loc.display()).as_slice());
675+
false
676+
});
667677

668-
// Now that we have an iterator of good candidates, make sure there's at
669-
// most one rlib and at most one dylib.
670-
let mut rlibs = HashSet::new();
671-
let mut dylibs = HashSet::new();
672-
for loc in locs {
673-
if loc.filename_str().unwrap().ends_with(".rlib") {
674-
rlibs.insert(fs::realpath(&loc).unwrap());
675-
} else {
676-
dylibs.insert(fs::realpath(&loc).unwrap());
678+
// Now that we have an iterator of good candidates, make sure there's at
679+
// most one rlib and at most one dylib.
680+
for loc in locs {
681+
if loc.filename_str().unwrap().ends_with(".rlib") {
682+
rlibs.insert(fs::realpath(&loc).unwrap());
683+
} else {
684+
dylibs.insert(fs::realpath(&loc).unwrap());
685+
}
677686
}
678-
}
687+
};
679688

680689
// Extract the rlib/dylib pair.
681690
let mut metadata = None;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: --extern std=
12+
// error-pattern: is not a file
13+
14+
fn main() {}

0 commit comments

Comments
 (0)