Skip to content

Commit 25147b2

Browse files
committed
auto merge of #12146 : gentlefolk/rust/issue-2404, r=alexcrichton
Addresses FIXME described in issue #2404
2 parents 5736deb + 37bf97a commit 25147b2

File tree

6 files changed

+74
-12
lines changed

6 files changed

+74
-12
lines changed

src/librustc/metadata/creader.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use syntax::ast;
2424
use syntax::abi;
2525
use syntax::attr;
2626
use syntax::attr::AttrMetaMethods;
27-
use syntax::codemap::{Span, DUMMY_SP};
27+
use syntax::codemap::{Span};
2828
use syntax::diagnostic::SpanHandler;
2929
use syntax::ext::base::{CrateLoader, MacroCrate};
3030
use syntax::parse::token::{IdentInterner, InternedString};
@@ -147,6 +147,7 @@ fn visit_view_item(e: &mut Env, i: &ast::ViewItem) {
147147
match extract_crate_info(i) {
148148
Some(info) => {
149149
let cnum = resolve_crate(e,
150+
None,
150151
info.ident.clone(),
151152
info.name.clone(),
152153
info.version.clone(),
@@ -299,6 +300,7 @@ fn existing_match(e: &Env, name: &str, version: &str, hash: &str) -> Option<ast:
299300
}
300301

301302
fn resolve_crate(e: &mut Env,
303+
root_ident: Option<~str>,
302304
ident: ~str,
303305
name: ~str,
304306
version: ~str,
@@ -319,7 +321,7 @@ fn resolve_crate(e: &mut Env,
319321
};
320322
let loader::Library {
321323
dylib, rlib, metadata
322-
} = load_ctxt.load_library_crate();
324+
} = load_ctxt.load_library_crate(root_ident.clone());
323325

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

343+
// Maintain a reference to the top most crate.
344+
let root_crate = match root_ident {
345+
Some(c) => c,
346+
None => load_ctxt.ident.clone()
347+
};
348+
341349
// Now resolve the crates referenced by this crate
342-
let cnum_map = resolve_crate_deps(e, metadata.as_slice());
350+
let cnum_map = resolve_crate_deps(e,
351+
Some(root_crate),
352+
metadata.as_slice(),
353+
span);
343354

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

366377
// Go through the crate metadata and load any crates that it references
367-
fn resolve_crate_deps(e: &mut Env, cdata: &[u8]) -> cstore::cnum_map {
378+
fn resolve_crate_deps(e: &mut Env,
379+
root_ident: Option<~str>,
380+
cdata: &[u8], span : Span)
381+
-> cstore::cnum_map {
368382
debug!("resolving deps of external crate");
369383
// The map from crate numbers in the crate we're resolving to local crate
370384
// numbers
@@ -387,15 +401,13 @@ fn resolve_crate_deps(e: &mut Env, cdata: &[u8]) -> cstore::cnum_map {
387401
None => {
388402
debug!("need to load it");
389403
// This is a new one so we've got to load it
390-
// FIXME (#2404): Need better error reporting than just a bogus
391-
// span.
392-
let fake_span = DUMMY_SP;
393404
let local_cnum = resolve_crate(e,
405+
root_ident.clone(),
394406
cname_str.get().to_str(),
395407
cname_str.get().to_str(),
396408
dep.vers.clone(),
397409
dep.hash.clone(),
398-
fake_span);
410+
span);
399411
cnum_map.insert(extrn_cnum, local_cnum);
400412
}
401413
}
@@ -427,6 +439,7 @@ impl CrateLoader for Loader {
427439
fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate {
428440
let info = extract_crate_info(krate).unwrap();
429441
let cnum = resolve_crate(&mut self.env,
442+
None,
430443
info.ident.clone(),
431444
info.name.clone(),
432445
info.version.clone(),

src/librustc/metadata/loader.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@ pub struct ArchiveMetadata {
6565
}
6666

6767
impl Context {
68-
pub fn load_library_crate(&self) -> Library {
68+
pub fn load_library_crate(&self, root_ident: Option<~str>) -> Library {
6969
match self.find_library_crate() {
7070
Some(t) => t,
7171
None => {
72-
self.sess.span_fatal(self.span,
73-
format!("can't find crate for `{}`",
74-
self.ident));
72+
let message = match root_ident {
73+
None => format!("can't find crate for `{}`", self.ident),
74+
Some(c) => format!("can't find crate for `{}` which `{}` depends on",
75+
self.ident,
76+
c)
77+
};
78+
self.sess.span_fatal(self.span, message);
7579
}
7680
}
7781
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) --crate-type=rlib crateA.rs
5+
$(RUSTC) --crate-type=rlib crateB.rs
6+
rm $(TMPDIR)/$(call RLIB_GLOB,crateA)
7+
# Ensure crateC fails to compile since dependency crateA is missing
8+
$(RUSTC) crateC.rs 2>&1 | \
9+
grep "error: can't find crate for \`crateA\` which \`crateB\` depends on"
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+
// Base crate
12+
pub fn func() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
extern crate crateA;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
extern crate crateB;
12+
13+
fn main() {}

0 commit comments

Comments
 (0)