From f069a57bb1fb4f4aae4e42a6ee75ad277bcf9f7f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 25 Jul 2018 18:02:03 -0700 Subject: [PATCH] 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 --- src/librustc_metadata/creader.rs | 7 +++---- .../extern-flag-rename-transitive/Makefile | 7 +++++++ .../extern-flag-rename-transitive/bar.rs | 13 +++++++++++++ .../extern-flag-rename-transitive/baz.rs | 14 ++++++++++++++ .../extern-flag-rename-transitive/foo.rs | 11 +++++++++++ 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/test/run-make-fulldeps/extern-flag-rename-transitive/Makefile create mode 100644 src/test/run-make-fulldeps/extern-flag-rename-transitive/bar.rs create mode 100644 src/test/run-make-fulldeps/extern-flag-rename-transitive/baz.rs create mode 100644 src/test/run-make-fulldeps/extern-flag-rename-transitive/foo.rs diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 1e227b8a1a6..f434da3f88d 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -188,13 +188,12 @@ impl<'a> CrateLoader<'a> { fn register_crate(&mut self, root: &Option, ident: Symbol, - name: Symbol, span: Span, lib: Library, dep_kind: DepKind) -> (CrateNum, Lrc) { - info!("register crate `extern crate {} as {}`", name, ident); let crate_root = lib.metadata.get_root(); + info!("register crate `extern crate {} as {}`", crate_root.name, ident); self.verify_no_symbol_conflicts(span, &crate_root); // Claim this crate number and cache it @@ -233,7 +232,7 @@ impl<'a> CrateLoader<'a> { .collect(); let cmeta = cstore::CrateMetadata { - name, + name: crate_root.name, extern_crate: Lock::new(None), def_path_table: Lrc::new(def_path_table), trait_impls, @@ -328,7 +327,7 @@ impl<'a> CrateLoader<'a> { (cnum, data) } LoadResult::Loaded(library) => { - self.register_crate(root, ident, name, span, library, dep_kind) + self.register_crate(root, ident, span, library, dep_kind) } } } diff --git a/src/test/run-make-fulldeps/extern-flag-rename-transitive/Makefile b/src/test/run-make-fulldeps/extern-flag-rename-transitive/Makefile new file mode 100644 index 00000000000..4354209a722 --- /dev/null +++ b/src/test/run-make-fulldeps/extern-flag-rename-transitive/Makefile @@ -0,0 +1,7 @@ +-include ../tools.mk + +all: + $(RUSTC) foo.rs + $(RUSTC) bar.rs + $(RUSTC) baz.rs --extern a=$(TMPDIR)/libfoo.rlib + diff --git a/src/test/run-make-fulldeps/extern-flag-rename-transitive/bar.rs b/src/test/run-make-fulldeps/extern-flag-rename-transitive/bar.rs new file mode 100644 index 00000000000..a14f3ba05b0 --- /dev/null +++ b/src/test/run-make-fulldeps/extern-flag-rename-transitive/bar.rs @@ -0,0 +1,13 @@ +// Copyright 2018 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "rlib"] + +extern crate foo; diff --git a/src/test/run-make-fulldeps/extern-flag-rename-transitive/baz.rs b/src/test/run-make-fulldeps/extern-flag-rename-transitive/baz.rs new file mode 100644 index 00000000000..a96c9f61c66 --- /dev/null +++ b/src/test/run-make-fulldeps/extern-flag-rename-transitive/baz.rs @@ -0,0 +1,14 @@ +// Copyright 2018 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "rlib"] + +extern crate a; +extern crate bar; diff --git a/src/test/run-make-fulldeps/extern-flag-rename-transitive/foo.rs b/src/test/run-make-fulldeps/extern-flag-rename-transitive/foo.rs new file mode 100644 index 00000000000..b18ce024718 --- /dev/null +++ b/src/test/run-make-fulldeps/extern-flag-rename-transitive/foo.rs @@ -0,0 +1,11 @@ +// Copyright 2018 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "rlib"]