Skip to content

Commit d1e549c

Browse files
Rollup merge of #52723 - alexcrichton:fix-extern-rename-ice, r=estebank
rustc: Register crates under their real names Whenever we register a crate into the crate store, make sure to use the real name mentioned in the metadata instead of the name mentioned in the `extern crate` statement, as the statement can be wrong! Closes #51796
2 parents 858adfe + f069a57 commit d1e549c

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

src/librustc_metadata/creader.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,12 @@ impl<'a> CrateLoader<'a> {
188188
fn register_crate(&mut self,
189189
root: &Option<CratePaths>,
190190
ident: Symbol,
191-
name: Symbol,
192191
span: Span,
193192
lib: Library,
194193
dep_kind: DepKind)
195194
-> (CrateNum, Lrc<cstore::CrateMetadata>) {
196-
info!("register crate `extern crate {} as {}`", name, ident);
197195
let crate_root = lib.metadata.get_root();
196+
info!("register crate `extern crate {} as {}`", crate_root.name, ident);
198197
self.verify_no_symbol_conflicts(span, &crate_root);
199198

200199
// Claim this crate number and cache it
@@ -233,7 +232,7 @@ impl<'a> CrateLoader<'a> {
233232
.collect();
234233

235234
let cmeta = cstore::CrateMetadata {
236-
name,
235+
name: crate_root.name,
237236
extern_crate: Lock::new(None),
238237
def_path_table: Lrc::new(def_path_table),
239238
trait_impls,
@@ -328,7 +327,7 @@ impl<'a> CrateLoader<'a> {
328327
(cnum, data)
329328
}
330329
LoadResult::Loaded(library) => {
331-
self.register_crate(root, ident, name, span, library, dep_kind)
330+
self.register_crate(root, ident, span, library, dep_kind)
332331
}
333332
}
334333
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) foo.rs
5+
$(RUSTC) bar.rs
6+
$(RUSTC) baz.rs --extern a=$(TMPDIR)/libfoo.rlib
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 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_type = "rlib"]
12+
13+
extern crate foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2018 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_type = "rlib"]
12+
13+
extern crate a;
14+
extern crate bar;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2018 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_type = "rlib"]

0 commit comments

Comments
 (0)