Skip to content

Commit bd30063

Browse files
committed
rustc: Implement re-export of renamed modules
Issue #1115
1 parent 25f7c84 commit bd30063

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

src/comp/metadata/csearch.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export get_tag_variants;
1212
export get_impls_for_mod;
1313
export get_impl_methods;
1414
export get_type;
15+
export get_item_name;
1516

1617
fn get_symbol(cstore: cstore::cstore, def: ast::def_id) -> str {
1718
let cdata = cstore::get_crate_data(cstore, def.crate).data;
@@ -93,6 +94,11 @@ fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_kinds_and_ty {
9394
decoder::get_type(cdata, def, tcx, resolver)
9495
}
9596

97+
fn get_item_name(cstore: cstore::cstore, cnum: int, id: int) -> ast::ident {
98+
let cdata = cstore::get_crate_data(cstore, cnum).data;
99+
ret decoder::lookup_item_name(cdata, id);
100+
}
101+
96102
// Translates a def_id from an external crate to a def_id for the current
97103
// compilation environment. We use this when trying to load types from
98104
// external crates - if those types further refer to types in other crates

src/comp/metadata/decoder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ fn lookup_item_name(data: @[u8], id: ast::node_id) -> ast::ident {
183183
item_name(lookup_item(id, data))
184184
}
185185

186-
// FIXME doesn't yet handle renamed re-exported externals
187186
fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
188187
ast::def {
189188
let item = lookup_item(did_.node, data);

src/comp/metadata/encoder.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,11 @@ fn encode_tag_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
250250
}
251251

252252
fn encode_info_for_mod(ebml_w: ebml::writer, md: _mod,
253-
id: node_id) {
253+
id: node_id, name: ident) {
254254
ebml::start_tag(ebml_w, tag_items_data_item);
255255
encode_def_id(ebml_w, local_def(id));
256256
encode_family(ebml_w, 'm' as u8);
257+
encode_name(ebml_w, name);
257258
for i in md.items {
258259
alt i.node {
259260
item_impl(_, _, _) {
@@ -300,12 +301,13 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
300301
ebml::end_tag(ebml_w);
301302
}
302303
item_mod(m) {
303-
encode_info_for_mod(ebml_w, m, item.id);
304+
encode_info_for_mod(ebml_w, m, item.id, item.ident);
304305
}
305306
item_native_mod(_) {
306307
ebml::start_tag(ebml_w, tag_items_data_item);
307308
encode_def_id(ebml_w, local_def(item.id));
308309
encode_family(ebml_w, 'n' as u8);
310+
encode_name(ebml_w, item.ident);
309311
ebml::end_tag(ebml_w);
310312
}
311313
item_ty(_, tps) {
@@ -434,7 +436,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer,
434436
let index: [entry<int>] = [];
435437
ebml::start_tag(ebml_w, tag_items_data);
436438
index += [{val: crate_node_id, pos: ebml_w.writer.tell()}];
437-
encode_info_for_mod(ebml_w, crate_mod, crate_node_id);
439+
encode_info_for_mod(ebml_w, crate_mod, crate_node_id, "");
438440
ecx.ccx.ast_map.items {|key, val|
439441
alt val {
440442
middle::ast_map::node_item(i) {

src/comp/middle/resolve.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,25 @@ fn ns_for_def(d: def) -> namespace {
13531353
fn lookup_external(e: env, cnum: int, ids: [ident], ns: namespace) ->
13541354
option::t<def> {
13551355
for d: def in csearch::lookup_defs(e.sess.get_cstore(), cnum, ids) {
1356-
e.ext_map.insert(def_id_of_def(d), ids);
1356+
let did = def_id_of_def(d);
1357+
alt d {
1358+
def_mod(_) | def_native_mod(_) {
1359+
// The [native] module name might have renamed when importing,
1360+
// find the original name for further lookup of names inside the
1361+
// [native] module
1362+
if did.crate != ast::local_crate {
1363+
let cname = cstore::get_crate_data(e.cstore, did.crate).name;
1364+
let name =
1365+
csearch::get_item_name(e.cstore, did.crate, did.node);
1366+
e.ext_map.insert(did, vec::init(ids) + [name]);
1367+
} else {
1368+
e.ext_map.insert(did, ids);
1369+
}
1370+
}
1371+
_ {
1372+
e.ext_map.insert(did, ids);
1373+
}
1374+
}
13571375
if ns == ns_for_def(d) { ret some(d); }
13581376
}
13591377
ret none::<def>;

0 commit comments

Comments
 (0)