rustc: Make resolve more forgiving of missing external crates

Rustdoc needs to be able to resolve locals without resolving externals
This commit is contained in:
Brian Anderson 2012-02-17 17:34:03 -08:00
parent cec1679cf6
commit 4e44437180
2 changed files with 16 additions and 7 deletions

View file

@ -20,7 +20,7 @@ export get_used_libraries;
export add_used_link_args; export add_used_link_args;
export get_used_link_args; export get_used_link_args;
export add_use_stmt_cnum; export add_use_stmt_cnum;
export get_use_stmt_cnum; export find_use_stmt_cnum;
export get_dep_hashes; export get_dep_hashes;
export get_path; export get_path;
@ -131,8 +131,9 @@ fn add_use_stmt_cnum(cstore: cstore, use_id: ast::node_id,
p(cstore).use_crate_map.insert(use_id, cnum); p(cstore).use_crate_map.insert(use_id, cnum);
} }
fn get_use_stmt_cnum(cstore: cstore, use_id: ast::node_id) -> ast::crate_num { fn find_use_stmt_cnum(cstore: cstore,
ret p(cstore).use_crate_map.get(use_id); use_id: ast::node_id) -> option<ast::crate_num> {
p(cstore).use_crate_map.find(use_id)
} }
// returns hashes of crates directly used by this crate. Hashes are // returns hashes of crates directly used by this crate. Hashes are

View file

@ -1285,9 +1285,17 @@ fn lookup_in_mod(e: env, m: def, sp: span, name: ident, ns: namespace,
} }
} }
fn found_view_item(e: env, id: node_id) -> def { fn found_view_item(e: env, id: node_id) -> option<def> {
let cnum = cstore::get_use_stmt_cnum(e.cstore, id); alt cstore::find_use_stmt_cnum(e.cstore, id) {
ret ast::def_mod({crate: cnum, node: ast::crate_node_id}); some(cnum) {
some(ast::def_mod({crate: cnum, node: ast::crate_node_id}))
}
none {
// This can happen if we didn't load external crate info.
// Rustdoc depends on this.
none
}
}
} }
fn lookup_import(e: env, defid: def_id, ns: namespace) -> option<def> { fn lookup_import(e: env, defid: def_id, ns: namespace) -> option<def> {
@ -1418,7 +1426,7 @@ fn lookup_in_mie(e: env, mie: mod_index_entry, ns: namespace) ->
option<def> { option<def> {
alt mie { alt mie {
mie_view_item(_, id, _) { mie_view_item(_, id, _) {
if ns == ns_module { ret some(found_view_item(e, id)); } if ns == ns_module { ret found_view_item(e, id); }
} }
mie_import_ident(id, _) { ret lookup_import(e, local_def(id), ns); } mie_import_ident(id, _) { ret lookup_import(e, local_def(id), ns); }
mie_item(item) { ret found_def_item(item, ns); } mie_item(item) { ret found_def_item(item, ns); }