Skip to content

Commit c716ad8

Browse files
committed
pull out encode_field
1 parent f351963 commit c716ad8

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

src/librustc_metadata/encoder.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,8 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
203203
debug!("encode_enum_variant_info(enum_did={:?})", enum_did);
204204
let ecx = self.ecx();
205205
let def = ecx.tcx.lookup_adt_def(enum_did);
206+
self.encode_fields(enum_did);
206207
for (i, variant) in def.variants.iter().enumerate() {
207-
for field in &variant.fields {
208-
self.encode_field(field);
209-
}
210208
self.record(variant.did, |this| this.encode_enum_variant_info(enum_did, i, vis));
211209
}
212210
}
@@ -415,25 +413,42 @@ fn encode_item_sort(rbml_w: &mut Encoder, sort: char) {
415413
}
416414

417415
impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
416+
fn encode_fields(&mut self,
417+
adt_def_id: DefId) {
418+
let def = self.ecx.tcx.lookup_adt_def(adt_def_id);
419+
for (variant_index, variant) in def.variants.iter().enumerate() {
420+
for (field_index, field) in variant.fields.iter().enumerate() {
421+
self.record(field.did, |this| this.encode_field(adt_def_id,
422+
variant_index,
423+
field_index));
424+
}
425+
}
426+
}
427+
}
428+
429+
impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
418430
fn encode_field(&mut self,
419-
field: ty::FieldDef<'tcx>) {
431+
adt_def_id: DefId,
432+
variant_index: usize,
433+
field_index: usize) {
420434
let ecx = self.ecx();
435+
let def = ecx.tcx.lookup_adt_def(adt_def_id);
436+
let variant = &def.variants[variant_index];
437+
let field = &variant.fields[field_index];
421438

422439
let nm = field.name;
423440
let id = ecx.local_id(field.did);
441+
debug!("encode_field: encoding {} {}", nm, id);
424442

425-
self.record(field.did, |this| {
426-
debug!("encode_field: encoding {} {}", nm, id);
427-
this.encode_struct_field_family(field.vis);
428-
encode_name(this.rbml_w, nm);
429-
this.encode_bounds_and_type_for_item(id);
430-
encode_def_id_and_key(ecx, this.rbml_w, field.did);
443+
self.encode_struct_field_family(field.vis);
444+
encode_name(self.rbml_w, nm);
445+
self.encode_bounds_and_type_for_item(id);
446+
encode_def_id_and_key(ecx, self.rbml_w, field.did);
431447

432-
let stab = ecx.tcx.lookup_stability(field.did);
433-
let depr = ecx.tcx.lookup_deprecation(field.did);
434-
encode_stability(this.rbml_w, stab);
435-
encode_deprecation(this.rbml_w, depr);
436-
});
448+
let stab = ecx.tcx.lookup_stability(field.did);
449+
let depr = ecx.tcx.lookup_deprecation(field.did);
450+
encode_stability(self.rbml_w, stab);
451+
encode_deprecation(self.rbml_w, depr);
437452
}
438453
}
439454

@@ -1064,9 +1079,7 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
10641079
let def = ecx.tcx.lookup_adt_def(def_id);
10651080
let variant = def.struct_variant();
10661081

1067-
for field in &variant.fields {
1068-
self.encode_field(field);
1069-
}
1082+
self.encode_fields(def_id);
10701083

10711084
// If this is a tuple-like struct, encode the type of the constructor.
10721085
match variant.kind {

0 commit comments

Comments
 (0)