Skip to content

Commit 0f53643

Browse files
committed
Auto merge of #28888 - arielb1:variant-ctor, r=eddyb
this makes the code cleaner, and is a complement to the cleanup on the HIR side. r? @eddyb
2 parents d0cae14 + 8afa176 commit 0f53643

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

src/librustc/metadata/decoder.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
388388
did: did,
389389
name: item_name(intr, item),
390390
fields: get_variant_fields(intr, cdata, item, tcx),
391-
ctor_id: did,
392391
disr_val: disr
393392
}
394393
}).collect()
@@ -417,13 +416,11 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
417416
cdata: Cmd,
418417
doc: rbml::Doc,
419418
did: DefId,
420-
ctor_id: DefId,
421419
tcx: &ty::ctxt<'tcx>) -> ty::VariantDefData<'tcx, 'tcx> {
422420
ty::VariantDefData {
423421
did: did,
424422
name: item_name(intr, doc),
425423
fields: get_variant_fields(intr, cdata, doc, tcx),
426-
ctor_id: ctor_id,
427424
disr_val: 0
428425
}
429426
}
@@ -440,7 +437,7 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
440437
reader::maybe_get_doc(doc, tag_items_data_item_struct_ctor).
441438
map_or(did, |ctor_doc| translated_def_id(cdata, ctor_doc));
442439
(ty::AdtKind::Struct,
443-
vec![get_struct_variant(intr, cdata, doc, did, ctor_did, tcx)])
440+
vec![get_struct_variant(intr, cdata, doc, ctor_did, tcx)])
444441
}
445442
_ => tcx.sess.bug(
446443
&format!("get_adt_def called on a non-ADT {:?} - {:?}",

src/librustc/middle/astencode.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,14 +1312,17 @@ fn copy_item_types(dcx: &DecodeContext, ii: &InlinedItem, orig_did: DefId) {
13121312
for (i_variant, orig_variant) in
13131313
def.variants.iter().zip(orig_def.variants.iter())
13141314
{
1315+
debug!("astencode: copying variant {:?} => {:?}",
1316+
orig_variant.did, i_variant.node.id);
13151317
copy_item_type(dcx, i_variant.node.id, orig_variant.did);
13161318
}
13171319
}
13181320
hir::ItemStruct(ref def, _) => {
13191321
if let Some(ctor_id) = def.ctor_id {
13201322
let ctor_did = dcx.tcx.lookup_adt_def(orig_did)
1321-
.struct_variant().ctor_id;
1322-
debug!("copying ctor {:?}", ctor_did);
1323+
.struct_variant().did;
1324+
debug!("astencode: copying ctor {:?} => {:?}", ctor_did,
1325+
ctor_id);
13231326
copy_item_type(dcx, ctor_id, ctor_did);
13241327
}
13251328
}

src/librustc/middle/ty/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,13 +1470,12 @@ pub type VariantDefMaster<'tcx> = &'tcx VariantDefData<'tcx, 'tcx>;
14701470
pub type FieldDefMaster<'tcx> = &'tcx FieldDefData<'tcx, 'tcx>;
14711471

14721472
pub struct VariantDefData<'tcx, 'container: 'tcx> {
1473+
/// The variant's DefId. If this is a tuple-like struct,
1474+
/// this is the DefId of the struct's ctor.
14731475
pub did: DefId,
14741476
pub name: Name, // struct's name if this is a struct
14751477
pub disr_val: Disr,
14761478
pub fields: Vec<FieldDefData<'tcx, 'container>>,
1477-
/// The DefId of the variant's ctor (unless the variant is a
1478-
/// tuple-like struct variant, this is just the variant's def-id).
1479-
pub ctor_id: DefId
14801479
}
14811480

14821481
pub struct FieldDefData<'tcx, 'container: 'tcx> {

src/librustc_typeck/collect.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,8 +1102,7 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
11021102
did: DefId,
11031103
name: ast::Name,
11041104
disr_val: ty::Disr,
1105-
def: &hir::StructDef,
1106-
ctor_id: DefId) -> ty::VariantDefData<'tcx, 'tcx> {
1105+
def: &hir::StructDef) -> ty::VariantDefData<'tcx, 'tcx> {
11071106
let mut seen_fields: FnvHashMap<ast::Name, Span> = FnvHashMap();
11081107
let fields = def.fields.iter().map(|f| {
11091108
let fid = tcx.map.local_def_id(f.node.id);
@@ -1130,8 +1129,7 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
11301129
did: did,
11311130
name: name,
11321131
disr_val: disr_val,
1133-
fields: fields,
1134-
ctor_id: ctor_id
1132+
fields: fields
11351133
}
11361134
}
11371135

@@ -1147,7 +1145,7 @@ fn convert_struct_def<'tcx>(tcx: &ty::ctxt<'tcx>,
11471145
tcx.intern_adt_def(
11481146
did,
11491147
ty::AdtKind::Struct,
1150-
vec![convert_struct_variant(tcx, did, it.name, 0, def, ctor_id)]
1148+
vec![convert_struct_variant(tcx, ctor_id, it.name, 0, def)]
11511149
)
11521150
}
11531151

@@ -1237,12 +1235,11 @@ fn convert_enum_def<'tcx>(tcx: &ty::ctxt<'tcx>,
12371235
special_idents::unnamed_field.name,
12381236
hir::Visibility::Public
12391237
)
1240-
}).collect(),
1241-
ctor_id: did
1238+
}).collect()
12421239
}
12431240
}
12441241
hir::StructVariantKind(ref def) => {
1245-
convert_struct_variant(tcx, did, name, disr, &def, did)
1242+
convert_struct_variant(tcx, did, name, disr, &def)
12461243
}
12471244
}
12481245
}

0 commit comments

Comments
 (0)