@@ -287,6 +287,15 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
287
287
for variant in & def. variants {
288
288
let vid = variant. did ;
289
289
assert ! ( vid. is_local( ) ) ;
290
+
291
+ if let ty:: VariantKind :: Dict = variant. kind ( ) {
292
+ // tuple-like enum variant fields aren't really items so
293
+ // don't try to encode them.
294
+ for field in & variant. fields {
295
+ encode_field ( ecx, rbml_w, field, index) ;
296
+ }
297
+ }
298
+
290
299
index. push ( entry {
291
300
val : vid. node as i64 ,
292
301
pos : rbml_w. mark_stable_position ( ) ,
@@ -308,11 +317,6 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
308
317
let stab = stability:: lookup ( ecx. tcx , vid) ;
309
318
encode_stability ( rbml_w, stab) ;
310
319
311
- if let ty:: VariantKind :: Dict = variant. kind ( ) {
312
- let idx = encode_info_for_struct ( ecx, rbml_w, variant, index) ;
313
- encode_index ( rbml_w, idx, write_i64) ;
314
- }
315
-
316
320
encode_struct_fields ( rbml_w, variant, vid) ;
317
321
318
322
let specified_disr_val = variant. disr_val ;
@@ -618,41 +622,29 @@ fn encode_provided_source(rbml_w: &mut Encoder,
618
622
}
619
623
}
620
624
621
- /* Returns an index of items in this class */
622
- fn encode_info_for_struct < ' a , ' tcx > ( ecx : & EncodeContext < ' a , ' tcx > ,
623
- rbml_w : & mut Encoder ,
624
- variant : ty:: VariantDef < ' tcx > ,
625
- global_index : & mut Vec < entry < i64 > > )
626
- -> Vec < entry < i64 > > {
627
- /* Each class has its own index, since different classes
628
- may have fields with the same name */
629
- let mut index = Vec :: new ( ) ;
630
- /* We encode both private and public fields -- need to include
631
- private fields to get the offsets right */
632
- for field in & variant. fields {
633
- let nm = field. name ;
634
- let id = field. did . node ;
635
-
636
- let pos = rbml_w. mark_stable_position ( ) ;
637
- index. push ( entry { val : id as i64 , pos : pos} ) ;
638
- global_index. push ( entry {
639
- val : id as i64 ,
640
- pos : pos,
641
- } ) ;
642
- rbml_w. start_tag ( tag_items_data_item) ;
643
- debug ! ( "encode_info_for_struct: doing {} {}" ,
644
- nm, id) ;
645
- encode_struct_field_family ( rbml_w, field. vis ) ;
646
- encode_name ( rbml_w, nm) ;
647
- encode_bounds_and_type_for_item ( rbml_w, ecx, id) ;
648
- encode_def_id ( rbml_w, DefId :: local ( id) ) ;
649
-
650
- let stab = stability:: lookup ( ecx. tcx , field. did ) ;
651
- encode_stability ( rbml_w, stab) ;
625
+ fn encode_field < ' a , ' tcx > ( ecx : & EncodeContext < ' a , ' tcx > ,
626
+ rbml_w : & mut Encoder ,
627
+ field : ty:: FieldDef < ' tcx > ,
628
+ global_index : & mut Vec < entry < i64 > > ) {
629
+ let nm = field. name ;
630
+ let id = field. did . node ;
652
631
653
- rbml_w. end_tag ( ) ;
654
- }
655
- index
632
+ let pos = rbml_w. mark_stable_position ( ) ;
633
+ global_index. push ( entry {
634
+ val : id as i64 ,
635
+ pos : pos,
636
+ } ) ;
637
+ rbml_w. start_tag ( tag_items_data_item) ;
638
+ debug ! ( "encode_field: encoding {} {}" , nm, id) ;
639
+ encode_struct_field_family ( rbml_w, field. vis ) ;
640
+ encode_name ( rbml_w, nm) ;
641
+ encode_bounds_and_type_for_item ( rbml_w, ecx, id) ;
642
+ encode_def_id ( rbml_w, DefId :: local ( id) ) ;
643
+
644
+ let stab = stability:: lookup ( ecx. tcx , field. did ) ;
645
+ encode_stability ( rbml_w, stab) ;
646
+
647
+ rbml_w. end_tag ( ) ;
656
648
}
657
649
658
650
fn encode_info_for_struct_ctor ( ecx : & EncodeContext ,
@@ -1146,11 +1138,9 @@ fn encode_info_for_item(ecx: &EncodeContext,
1146
1138
let def = ecx. tcx . lookup_adt_def ( def_id) ;
1147
1139
let variant = def. struct_variant ( ) ;
1148
1140
1149
- /* First, encode the fields
1150
- These come first because we need to write them to make
1151
- the index, and the index needs to be in the item for the
1152
- class itself */
1153
- let idx = encode_info_for_struct ( ecx, rbml_w, variant, index) ;
1141
+ for field in & variant. fields {
1142
+ encode_field ( ecx, rbml_w, field, index) ;
1143
+ }
1154
1144
1155
1145
/* Index the class*/
1156
1146
add_to_index ( item, rbml_w, index) ;
@@ -1179,8 +1169,6 @@ fn encode_info_for_item(ecx: &EncodeContext,
1179
1169
// Encode inherent implementations for this structure.
1180
1170
encode_inherent_implementations ( ecx, rbml_w, def_id) ;
1181
1171
1182
- /* Each class has its own index -- encode it */
1183
- encode_index ( rbml_w, idx, write_i64) ;
1184
1172
rbml_w. end_tag ( ) ;
1185
1173
1186
1174
// If this is a tuple-like struct, encode the type of the constructor.
0 commit comments