From f9888ac33980aeb866fe2f904f2da436099136e5 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Thu, 11 Sep 2014 22:49:41 -0700 Subject: [PATCH 1/3] Make debug message about resolving `extern crate` statements more helpful --- src/librustc/metadata/creader.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 321eee3d5fc..9931f47a133 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -145,7 +145,7 @@ fn extract_crate_info(e: &Env, i: &ast::ViewItem) -> Option { match i.node { ast::ViewItemExternCrate(ident, ref path_opt, id) => { let ident = token::get_ident(ident); - debug!("resolving extern crate stmt. ident: {:?} path_opt: {:?}", + debug!("resolving extern crate stmt. ident: {} path_opt: {}", ident, path_opt); let name = match *path_opt { Some((ref path_str, _)) => { From 957229c21504c734c49a94f1685f82ac225df3e7 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Thu, 11 Sep 2014 22:50:40 -0700 Subject: [PATCH 2/3] Fix check for existing crate when using --extern When checking for an existing crate, compare against the `crate_metadata::name` field, which is the crate name which was requested during resolution, rather than the result of the `crate_metadata::name()` method, which is the crate name within the crate metadata, as these may not match when using the --extern option to `rustc`. This fixes spurious "multiple crate version" warnings under the following scenario: - The crate `foo`, is referenced multiple times - `--extern foo=./path/to/libbar.rlib` is specified to rustc - The internal crate name of `libbar.rlib` is not `foo` The behavior surrounding `Context::should_match_name` and the comments in `loader.rs` both lead me to believe that this scenario is intended to work. Fixes #17186 --- src/librustc/metadata/creader.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 9931f47a133..b551e9ce34f 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -281,7 +281,7 @@ fn existing_match(e: &Env, name: &str, hash: Option<&Svh>) -> Option { let mut ret = None; e.sess.cstore.iter_crate_data(|cnum, data| { - if data.name().as_slice() != name { return } + if data.name.as_slice() != name { return } match hash { Some(hash) if *hash == data.hash() => { ret = Some(cnum); return } From 3da255d35a7f9d53e4c31d5712f88ff14eaaf45e Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Fri, 12 Sep 2014 08:38:45 -0700 Subject: [PATCH 3/3] Add regression test for #17186 --- .../run-make/extern-diff-internal-name/Makefile | 6 ++++++ .../run-make/extern-diff-internal-name/lib.rs | 12 ++++++++++++ .../run-make/extern-diff-internal-name/test.rs | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/test/run-make/extern-diff-internal-name/Makefile create mode 100644 src/test/run-make/extern-diff-internal-name/lib.rs create mode 100644 src/test/run-make/extern-diff-internal-name/test.rs diff --git a/src/test/run-make/extern-diff-internal-name/Makefile b/src/test/run-make/extern-diff-internal-name/Makefile new file mode 100644 index 00000000000..3787b879c1f --- /dev/null +++ b/src/test/run-make/extern-diff-internal-name/Makefile @@ -0,0 +1,6 @@ +-include ../tools.mk + +all: + $(RUSTC) lib.rs + $(RUSTC) test.rs --extern foo=$(TMPDIR)/libbar.rlib 2>&1 | \ + { ! grep "using multiple versions of crate"; } diff --git a/src/test/run-make/extern-diff-internal-name/lib.rs b/src/test/run-make/extern-diff-internal-name/lib.rs new file mode 100644 index 00000000000..e8779bba13c --- /dev/null +++ b/src/test/run-make/extern-diff-internal-name/lib.rs @@ -0,0 +1,12 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_name = "bar"] +#![crate_type = "rlib"] diff --git a/src/test/run-make/extern-diff-internal-name/test.rs b/src/test/run-make/extern-diff-internal-name/test.rs new file mode 100644 index 00000000000..ab1cf96999d --- /dev/null +++ b/src/test/run-make/extern-diff-internal-name/test.rs @@ -0,0 +1,17 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(phase)] + +#[phase(plugin, link)] +extern crate foo; + +fn main() { +}