]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #17189 : bkoropoff/rust/extern-existing-crate, r=alexcrichton
authorbors <bors@rust-lang.org>
Sun, 14 Sep 2014 00:51:05 +0000 (00:51 +0000)
committerbors <bors@rust-lang.org>
Sun, 14 Sep 2014 00:51:05 +0000 (00:51 +0000)
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

1  2 
src/librustc/metadata/creader.rs

index 8c17c16afee1b11b8bbe2ba44ee9316d6e78ea32,b551e9ce34fc5886674984174df2d2fc2d844e2c..b82c9c93376e2b5d4ca186ed79219f1006ac18ae
@@@ -49,19 -49,19 +49,19 @@@ pub fn read_crates(sess: &Session
          next_crate_num: sess.cstore.next_crate_num(),
      };
      visit_crate(&e, krate);
 -    visit::walk_crate(&mut e, krate, ());
 +    visit::walk_crate(&mut e, krate);
      dump_crates(&sess.cstore);
      warn_if_multiple_versions(sess.diagnostic(), &sess.cstore)
  }
  
 -impl<'a> visit::Visitor<()> for Env<'a> {
 -    fn visit_view_item(&mut self, a: &ast::ViewItem, _: ()) {
 +impl<'a, 'v> visit::Visitor<'v> for Env<'a> {
 +    fn visit_view_item(&mut self, a: &ast::ViewItem) {
          visit_view_item(self, a);
 -        visit::walk_view_item(self, a, ());
 +        visit::walk_view_item(self, a);
      }
 -    fn visit_item(&mut self, a: &ast::Item, _: ()) {
 +    fn visit_item(&mut self, a: &ast::Item) {
          visit_item(self, a);
 -        visit::walk_item(self, a, ());
 +        visit::walk_item(self, a);
      }
  }
  
@@@ -145,7 -145,7 +145,7 @@@ fn extract_crate_info(e: &Env, i: &ast:
      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, _)) => {
@@@ -281,7 -281,7 +281,7 @@@ fn existing_match(e: &Env, name: &str
                    hash: Option<&Svh>) -> Option<ast::CrateNum> {
      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 }