Skip to content

Commit b0d85e3

Browse files
committed
rustc: Don't die when a crate id can't be inferred
The filestem of the desired output isn't necessarily a valid crate id, and calling unwrap() will trigger an ICE in rustc. This tries a little harder to infer a "valid crate id" from a crate, with an eventual fallback to a generic crate id if alll else fails. Closes #11107
1 parent c62daa6 commit b0d85e3

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/librustc/back/link.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,10 @@ pub mod write {
516516

517517
pub fn find_crate_id(attrs: &[ast::Attribute], out_filestem: &str) -> CrateId {
518518
match attr::find_crateid(attrs) {
519-
None => from_str(out_filestem).unwrap(),
519+
None => from_str(out_filestem).unwrap_or_else(|| {
520+
let mut s = out_filestem.chars().filter(|c| c.is_XID_continue());
521+
from_str(s.collect::<~str>()).or(from_str("rust-out")).unwrap()
522+
}),
520523
Some(s) => s,
521524
}
522525
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) foo.rs -o $(TMPDIR)/.foo
5+
rm $(TMPDIR)/.foo
6+
$(RUSTC) foo.rs -o $(TMPDIR)/.foo.bar
7+
rm $(TMPDIR)/.foo.bar
8+
$(RUSTC) foo.rs -o $(TMPDIR)/+foo+bar
9+
rm $(TMPDIR)/+foo+bar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
fn main() {}

0 commit comments

Comments
 (0)