Skip to content

Commit f1acc69

Browse files
committed
Add class fields to the global index
Closes #2192
1 parent b837f37 commit f1acc69

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/rustc/metadata/decoder.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,11 @@ fn read_path(d: ebml::doc) -> {path: str, pos: uint} {
546546

547547
fn describe_def(items: ebml::doc, id: ast::def_id) -> str {
548548
if id.crate != ast::local_crate { ret "external"; }
549-
ret item_family_to_str(item_family(find_item(id.node, items)));
549+
let it = alt maybe_find_item(id.node, items) {
550+
some(it) { it }
551+
none { fail (#fmt("describe_def: item not found %?", id)); }
552+
};
553+
ret item_family_to_str(item_family(it));
550554
}
551555

552556
fn item_family_to_str(fam: char) -> str {
@@ -567,6 +571,8 @@ fn item_family_to_str(fam: char) -> str {
567571
'i' { ret "impl"; }
568572
'I' { ret "iface"; }
569573
'C' { ret "class"; }
574+
'g' { ret "public field"; }
575+
'j' { ret "private field"; }
570576
}
571577
}
572578

src/rustc/metadata/encoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
191191
encode_name_and_def_id(ebml_w, it.ident, it.id);
192192
}
193193
ebml_w.wr_tag(tag_paths) {||
194-
// As in the res case, we add the same ident twice: for the
194+
// We add the same ident twice: for the
195195
// class and for its ctor
196196
add_to_index(ebml_w, path, index, it.ident);
197197
encode_named_def_id(ebml_w, it.ident,
@@ -422,8 +422,9 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer,
422422
id: node_id, path: ast_map::path,
423423
class_tps: [ty_param],
424424
items: [@class_member],
425-
global_index: @mut[entry<int>])
426-
-> [entry<int>] {
425+
global_index: @mut[entry<int>]) -> [entry<int>] {
426+
/* Each class has its own index, since different classes
427+
may have fields with the same name */
427428
let index = @mut [];
428429
let tcx = ecx.tcx;
429430
for items.each {|ci|
@@ -432,6 +433,7 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer,
432433
alt ci.node {
433434
instance_var(nm, _, mt, id, vis) {
434435
*index += [{val: id, pos: ebml_w.writer.tell()}];
436+
*global_index += [{val: id, pos: ebml_w.writer.tell()}];
435437
ebml_w.start_tag(tag_items_data_item);
436438
#debug("encode_info_for_class: doing %s %d", *nm, id);
437439
encode_visibility(ebml_w, vis);
@@ -446,8 +448,6 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer,
446448
alt m.vis {
447449
public {
448450
*index += [{val: m.id, pos: ebml_w.writer.tell()}];
449-
/* Not sure whether we really need to have two indices,
450-
but it works for now -- tjc */
451451
*global_index += [{val: m.id, pos: ebml_w.writer.tell()}];
452452
let impl_path = path + [ast_map::path_name(m.ident)];
453453
#debug("encode_info_for_class: doing %s %d", *m.ident, m.id);

src/test/run-pass/issue-2192.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[crate_type = "lib"];
2+
3+
class foo {
4+
let mut x: int;
5+
new(xx: int) { self.x = xx; }
6+
}

0 commit comments

Comments
 (0)