Skip to content

Commit 931b115

Browse files
committed
auto merge of #17189 : bkoropoff/rust/extern-existing-crate, r=alexcrichton
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
2 parents 79a5448 + 3da255d commit 931b115

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/librustc/metadata/creader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn extract_crate_info(e: &Env, i: &ast::ViewItem) -> Option<CrateInfo> {
145145
match i.node {
146146
ast::ViewItemExternCrate(ident, ref path_opt, id) => {
147147
let ident = token::get_ident(ident);
148-
debug!("resolving extern crate stmt. ident: {:?} path_opt: {:?}",
148+
debug!("resolving extern crate stmt. ident: {} path_opt: {}",
149149
ident, path_opt);
150150
let name = match *path_opt {
151151
Some((ref path_str, _)) => {
@@ -281,7 +281,7 @@ fn existing_match(e: &Env, name: &str,
281281
hash: Option<&Svh>) -> Option<ast::CrateNum> {
282282
let mut ret = None;
283283
e.sess.cstore.iter_crate_data(|cnum, data| {
284-
if data.name().as_slice() != name { return }
284+
if data.name.as_slice() != name { return }
285285

286286
match hash {
287287
Some(hash) if *hash == data.hash() => { ret = Some(cnum); return }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) lib.rs
5+
$(RUSTC) test.rs --extern foo=$(TMPDIR)/libbar.rlib 2>&1 | \
6+
{ ! grep "using multiple versions of crate"; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 = "bar"]
12+
#![crate_type = "rlib"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
#![feature(phase)]
12+
13+
#[phase(plugin, link)]
14+
extern crate foo;
15+
16+
fn main() {
17+
}

0 commit comments

Comments
 (0)