Skip to content

Commit bfe4ddf

Browse files
committed
auto merge of rust-lang#15518 : alexcrichton/rust/fix-some-crate-names, r=sfackler
The output file was only being renamed based off #[crate_name], not #[crate_id] or --crate-name. Both of these behaviors have been restored now.
2 parents e2e237a + 2c26a00 commit bfe4ddf

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

src/librustc/driver/driver.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,21 @@ pub fn build_output_filenames(input: &Input,
903903
};
904904

905905
// If a crate name is present, we use it as the link name
906-
let stem = match attr::find_crate_name(attrs) {
907-
None => input.filestem(),
908-
Some(name) => name.get().to_string(),
909-
};
906+
let stem = sess.opts.crate_name.clone().or_else(|| {
907+
attr::find_crate_name(attrs).map(|n| n.get().to_string())
908+
}).or_else(|| {
909+
// NB: this clause can be removed once #[crate_id] is no longer
910+
// deprecated.
911+
//
912+
// Also note that this will be warned about later so we don't
913+
// warn about it here.
914+
use syntax::crateid::CrateId;
915+
attrs.iter().find(|at| at.check_name("crate_id"))
916+
.and_then(|at| at.value_str())
917+
.and_then(|s| from_str::<CrateId>(s.get()))
918+
.map(|id| id.name)
919+
}).unwrap_or(input.filestem());
920+
910921
OutputFilenames {
911922
out_directory: dirpath,
912923
out_filestem: stem,

src/librustc/lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,12 @@ impl LintPass for UnusedAttribute {
575575
];
576576

577577
static CRATE_ATTRS: &'static [&'static str] = &[
578+
"crate_name",
578579
"crate_type",
579580
"feature",
580581
"no_start",
581582
"no_main",
582583
"no_std",
583-
"crate_id",
584584
"desc",
585585
"comment",
586586
"license",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) foo.rs
5+
rm $(TMPDIR)/$(call BIN,foo)
6+
$(RUSTC) foo.rs --crate-name bar
7+
rm $(TMPDIR)/$(call BIN,bar)
8+
$(RUSTC) foo1.rs
9+
rm $(TMPDIR)/$(call BIN,foo)
10+
$(RUSTC) foo1.rs --crate-name bar
11+
rm $(TMPDIR)/$(call BIN,bar)
12+
$(RUSTC) foo1.rs --crate-name bar -o $(TMPDIR)/bar1
13+
rm $(TMPDIR)/$(call BIN,bar1)
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() {}
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+
#![crate_name = "foo"]
12+
13+
fn main() {}
14+

0 commit comments

Comments
 (0)