@@ -203,10 +203,8 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
203
203
debug ! ( "encode_enum_variant_info(enum_did={:?})" , enum_did) ;
204
204
let ecx = self . ecx ( ) ;
205
205
let def = ecx. tcx . lookup_adt_def ( enum_did) ;
206
+ self . encode_fields ( enum_did) ;
206
207
for ( i, variant) in def. variants . iter ( ) . enumerate ( ) {
207
- for field in & variant. fields {
208
- self . encode_field ( field) ;
209
- }
210
208
self . record ( variant. did , |this| this. encode_enum_variant_info ( enum_did, i, vis) ) ;
211
209
}
212
210
}
@@ -415,25 +413,42 @@ fn encode_item_sort(rbml_w: &mut Encoder, sort: char) {
415
413
}
416
414
417
415
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 > {
418
430
fn encode_field ( & mut self ,
419
- field : ty:: FieldDef < ' tcx > ) {
431
+ adt_def_id : DefId ,
432
+ variant_index : usize ,
433
+ field_index : usize ) {
420
434
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] ;
421
438
422
439
let nm = field. name ;
423
440
let id = ecx. local_id ( field. did ) ;
441
+ debug ! ( "encode_field: encoding {} {}" , nm, id) ;
424
442
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 ) ;
431
447
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) ;
437
452
}
438
453
}
439
454
@@ -1064,9 +1079,7 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
1064
1079
let def = ecx. tcx . lookup_adt_def ( def_id) ;
1065
1080
let variant = def. struct_variant ( ) ;
1066
1081
1067
- for field in & variant. fields {
1068
- self . encode_field ( field) ;
1069
- }
1082
+ self . encode_fields ( def_id) ;
1070
1083
1071
1084
// If this is a tuple-like struct, encode the type of the constructor.
1072
1085
match variant. kind {
0 commit comments