]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Don't die when a crate id can't be inferred
authorAlex Crichton <alex@alexcrichton.com>
Tue, 15 Apr 2014 14:47:26 +0000 (07:47 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 23 Apr 2014 17:04:29 +0000 (10:04 -0700)
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

src/librustc/back/link.rs
src/test/run-make/weird-output-filenames/Makefile [new file with mode: 0644]
src/test/run-make/weird-output-filenames/foo.rs [new file with mode: 0644]

index f6846acaa99188b787aa63efa786119a1e38ae34..17a09aa49090175f56d21e4896d71edc0d9d92c7 100644 (file)
@@ -516,7 +516,10 @@ unsafe fn populate_llvm_passes(fpm: lib::llvm::PassManagerRef,
 
 pub fn find_crate_id(attrs: &[ast::Attribute], out_filestem: &str) -> CrateId {
     match attr::find_crateid(attrs) {
-        None => from_str(out_filestem).unwrap(),
+        None => from_str(out_filestem).unwrap_or_else(|| {
+            let mut s = out_filestem.chars().filter(|c| c.is_XID_continue());
+            from_str(s.collect::<~str>()).or(from_str("rust-out")).unwrap()
+        }),
         Some(s) => s,
     }
 }
diff --git a/src/test/run-make/weird-output-filenames/Makefile b/src/test/run-make/weird-output-filenames/Makefile
new file mode 100644 (file)
index 0000000..9d852bc
--- /dev/null
@@ -0,0 +1,9 @@
+-include ../tools.mk
+
+all:
+       $(RUSTC) foo.rs -o $(TMPDIR)/.foo
+       rm $(TMPDIR)/.foo
+       $(RUSTC) foo.rs -o $(TMPDIR)/.foo.bar
+       rm $(TMPDIR)/.foo.bar
+       $(RUSTC) foo.rs -o $(TMPDIR)/+foo+bar
+       rm $(TMPDIR)/+foo+bar
diff --git a/src/test/run-make/weird-output-filenames/foo.rs b/src/test/run-make/weird-output-filenames/foo.rs
new file mode 100644 (file)
index 0000000..8ae3d07
--- /dev/null
@@ -0,0 +1,11 @@
+// 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.
+
+fn main() {}