Skip to content
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

use the struct's ctor-id as its variant def-id #28888

Merged
merged 1 commit into from
Oct 9, 2015
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
5 changes: 1 addition & 4 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
did: did,
name: item_name(intr, item),
fields: get_variant_fields(intr, cdata, item, tcx),
ctor_id: did,
disr_val: disr
}
}).collect()
Expand Down Expand Up @@ -417,13 +416,11 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
cdata: Cmd,
doc: rbml::Doc,
did: DefId,
ctor_id: DefId,
tcx: &ty::ctxt<'tcx>) -> ty::VariantDefData<'tcx, 'tcx> {
ty::VariantDefData {
did: did,
name: item_name(intr, doc),
fields: get_variant_fields(intr, cdata, doc, tcx),
ctor_id: ctor_id,
disr_val: 0
}
}
Expand All @@ -440,7 +437,7 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
reader::maybe_get_doc(doc, tag_items_data_item_struct_ctor).
map_or(did, |ctor_doc| translated_def_id(cdata, ctor_doc));
(ty::AdtKind::Struct,
vec![get_struct_variant(intr, cdata, doc, did, ctor_did, tcx)])
vec![get_struct_variant(intr, cdata, doc, ctor_did, tcx)])
}
_ => tcx.sess.bug(
&format!("get_adt_def called on a non-ADT {:?} - {:?}",
Expand Down
7 changes: 5 additions & 2 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,14 +1312,17 @@ fn copy_item_types(dcx: &DecodeContext, ii: &InlinedItem, orig_did: DefId) {
for (i_variant, orig_variant) in
def.variants.iter().zip(orig_def.variants.iter())
{
debug!("astencode: copying variant {:?} => {:?}",
orig_variant.did, i_variant.node.id);
copy_item_type(dcx, i_variant.node.id, orig_variant.did);
}
}
hir::ItemStruct(ref def, _) => {
if let Some(ctor_id) = def.ctor_id {
let ctor_did = dcx.tcx.lookup_adt_def(orig_did)
.struct_variant().ctor_id;
debug!("copying ctor {:?}", ctor_did);
.struct_variant().did;
debug!("astencode: copying ctor {:?} => {:?}", ctor_did,
ctor_id);
copy_item_type(dcx, ctor_id, ctor_did);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,13 +1470,12 @@ pub type VariantDefMaster<'tcx> = &'tcx VariantDefData<'tcx, 'tcx>;
pub type FieldDefMaster<'tcx> = &'tcx FieldDefData<'tcx, 'tcx>;

pub struct VariantDefData<'tcx, 'container: 'tcx> {
/// The variant's DefId. If this is a tuple-like struct,
/// this is the DefId of the struct's ctor.
pub did: DefId,
pub name: Name, // struct's name if this is a struct
pub disr_val: Disr,
pub fields: Vec<FieldDefData<'tcx, 'container>>,
/// The DefId of the variant's ctor (unless the variant is a
/// tuple-like struct variant, this is just the variant's def-id).
pub ctor_id: DefId
}

pub struct FieldDefData<'tcx, 'container: 'tcx> {
Expand Down
13 changes: 5 additions & 8 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,8 +1102,7 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
did: DefId,
name: ast::Name,
disr_val: ty::Disr,
def: &hir::StructDef,
ctor_id: DefId) -> ty::VariantDefData<'tcx, 'tcx> {
def: &hir::StructDef) -> ty::VariantDefData<'tcx, 'tcx> {
let mut seen_fields: FnvHashMap<ast::Name, Span> = FnvHashMap();
let fields = def.fields.iter().map(|f| {
let fid = tcx.map.local_def_id(f.node.id);
Expand All @@ -1130,8 +1129,7 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
did: did,
name: name,
disr_val: disr_val,
fields: fields,
ctor_id: ctor_id
fields: fields
}
}

Expand All @@ -1147,7 +1145,7 @@ fn convert_struct_def<'tcx>(tcx: &ty::ctxt<'tcx>,
tcx.intern_adt_def(
did,
ty::AdtKind::Struct,
vec![convert_struct_variant(tcx, did, it.name, 0, def, ctor_id)]
vec![convert_struct_variant(tcx, ctor_id, it.name, 0, def)]
)
}

Expand Down Expand Up @@ -1237,12 +1235,11 @@ fn convert_enum_def<'tcx>(tcx: &ty::ctxt<'tcx>,
special_idents::unnamed_field.name,
hir::Visibility::Public
)
}).collect(),
ctor_id: did
}).collect()
}
}
hir::StructVariantKind(ref def) => {
convert_struct_variant(tcx, did, name, disr, &def, did)
convert_struct_variant(tcx, did, name, disr, &def)
}
}
}
Expand Down