Skip to content

Updated metadata::creader::resolve_crate_deps to use the correct span #12146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use syntax::ast;
use syntax::abi;
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::codemap::{Span, DUMMY_SP};
use syntax::codemap::{Span};
use syntax::diagnostic::SpanHandler;
use syntax::ext::base::{CrateLoader, MacroCrate};
use syntax::parse::token::{IdentInterner, InternedString};
Expand Down Expand Up @@ -147,6 +147,7 @@ fn visit_view_item(e: &mut Env, i: &ast::ViewItem) {
match extract_crate_info(i) {
Some(info) => {
let cnum = resolve_crate(e,
None,
info.ident.clone(),
info.name.clone(),
info.version.clone(),
Expand Down Expand Up @@ -299,6 +300,7 @@ fn existing_match(e: &Env, name: &str, version: &str, hash: &str) -> Option<ast:
}

fn resolve_crate(e: &mut Env,
root_ident: Option<~str>,
ident: ~str,
name: ~str,
version: ~str,
Expand All @@ -319,7 +321,7 @@ fn resolve_crate(e: &mut Env,
};
let loader::Library {
dylib, rlib, metadata
} = load_ctxt.load_library_crate();
} = load_ctxt.load_library_crate(root_ident.clone());

let attrs = decoder::get_crate_attributes(metadata.as_slice());
let crateid = attr::find_crateid(attrs).unwrap();
Expand All @@ -338,8 +340,17 @@ fn resolve_crate(e: &mut Env,
}
e.next_crate_num += 1;

// Maintain a reference to the top most crate.
let root_crate = match root_ident {
Some(c) => c,
None => load_ctxt.ident.clone()
};

// Now resolve the crates referenced by this crate
let cnum_map = resolve_crate_deps(e, metadata.as_slice());
let cnum_map = resolve_crate_deps(e,
Some(root_crate),
metadata.as_slice(),
span);

let cmeta = @cstore::crate_metadata {
name: load_ctxt.name,
Expand All @@ -364,7 +375,10 @@ fn resolve_crate(e: &mut Env,
}

// Go through the crate metadata and load any crates that it references
fn resolve_crate_deps(e: &mut Env, cdata: &[u8]) -> cstore::cnum_map {
fn resolve_crate_deps(e: &mut Env,
root_ident: Option<~str>,
cdata: &[u8], span : Span)
-> cstore::cnum_map {
debug!("resolving deps of external crate");
// The map from crate numbers in the crate we're resolving to local crate
// numbers
Expand All @@ -387,15 +401,13 @@ fn resolve_crate_deps(e: &mut Env, cdata: &[u8]) -> cstore::cnum_map {
None => {
debug!("need to load it");
// This is a new one so we've got to load it
// FIXME (#2404): Need better error reporting than just a bogus
// span.
let fake_span = DUMMY_SP;
let local_cnum = resolve_crate(e,
root_ident.clone(),
cname_str.get().to_str(),
cname_str.get().to_str(),
dep.vers.clone(),
dep.hash.clone(),
fake_span);
span);
cnum_map.insert(extrn_cnum, local_cnum);
}
}
Expand Down Expand Up @@ -427,6 +439,7 @@ impl CrateLoader for Loader {
fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate {
let info = extract_crate_info(krate).unwrap();
let cnum = resolve_crate(&mut self.env,
None,
info.ident.clone(),
info.name.clone(),
info.version.clone(),
Expand Down
12 changes: 8 additions & 4 deletions src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ pub struct ArchiveMetadata {
}

impl Context {
pub fn load_library_crate(&self) -> Library {
pub fn load_library_crate(&self, root_ident: Option<~str>) -> Library {
match self.find_library_crate() {
Some(t) => t,
None => {
self.sess.span_fatal(self.span,
format!("can't find crate for `{}`",
self.ident));
let message = match root_ident {
None => format!("can't find crate for `{}`", self.ident),
Some(c) => format!("can't find crate for `{}` which `{}` depends on",
self.ident,
c)
};
self.sess.span_fatal(self.span, message);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/run-make/missing-crate-dependency/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-include ../tools.mk

all:
$(RUSTC) --crate-type=rlib crateA.rs
$(RUSTC) --crate-type=rlib crateB.rs
rm $(TMPDIR)/$(call RLIB_GLOB,crateA)
# Ensure crateC fails to compile since dependency crateA is missing
$(RUSTC) crateC.rs 2>&1 | \
grep "error: can't find crate for \`crateA\` which \`crateB\` depends on"
12 changes: 12 additions & 0 deletions src/test/run-make/missing-crate-dependency/crateA.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Base crate
pub fn func() {}
11 changes: 11 additions & 0 deletions src/test/run-make/missing-crate-dependency/crateB.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate crateA;
13 changes: 13 additions & 0 deletions src/test/run-make/missing-crate-dependency/crateC.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate crateB;

fn main() {}