@@ -41,7 +41,6 @@ use syntax::attr::AttrMetaMethods;
41
41
use syntax:: diagnostic:: SpanHandler ;
42
42
use syntax:: parse:: token:: special_idents;
43
43
use syntax:: print:: pprust;
44
- use syntax:: ptr:: P ;
45
44
use syntax:: visit:: Visitor ;
46
45
use syntax:: visit;
47
46
use syntax;
@@ -266,7 +265,7 @@ fn encode_parent_item(rbml_w: &mut Encoder, id: DefId) {
266
265
}
267
266
268
267
fn encode_struct_fields ( rbml_w : & mut Encoder ,
269
- fields : & [ ty:: FieldTy ] ,
268
+ fields : & [ ty:: FieldDef ] ,
270
269
origin : DefId ) {
271
270
for f in fields {
272
271
if f. name == special_idents:: unnamed_field. name {
@@ -276,7 +275,7 @@ fn encode_struct_fields(rbml_w: &mut Encoder,
276
275
encode_name ( rbml_w, f. name ) ;
277
276
}
278
277
encode_struct_field_family ( rbml_w, f. vis ) ;
279
- encode_def_id ( rbml_w, f. id ) ;
278
+ encode_def_id ( rbml_w, f. did ) ;
280
279
rbml_w. wr_tagged_u64 ( tag_item_field_origin, def_to_u64 ( origin) ) ;
281
280
rbml_w. end_tag ( ) ;
282
281
}
@@ -285,57 +284,56 @@ fn encode_struct_fields(rbml_w: &mut Encoder,
285
284
fn encode_enum_variant_info ( ecx : & EncodeContext ,
286
285
rbml_w : & mut Encoder ,
287
286
id : NodeId ,
288
- variants : & [ P < ast:: Variant > ] ,
287
+ vis : ast:: Visibility ,
289
288
index : & mut Vec < entry < i64 > > ) {
290
289
debug ! ( "encode_enum_variant_info(id={})" , id) ;
291
290
292
291
let mut disr_val = 0 ;
293
- let mut i = 0 ;
294
- let vi = ecx . tcx . enum_variants ( local_def ( id ) ) ;
295
- for variant in variants {
296
- let def_id = local_def ( variant . node . id ) ;
292
+ let def = ecx . tcx . lookup_adt_def ( local_def ( id ) ) ;
293
+ for variant in & def . variants {
294
+ let vid = variant . did ;
295
+ assert ! ( is_local ( vid ) ) ;
297
296
index. push ( entry {
298
- val : variant . node . id as i64 ,
297
+ val : vid . node as i64 ,
299
298
pos : rbml_w. mark_stable_position ( ) ,
300
299
} ) ;
301
300
rbml_w. start_tag ( tag_items_data_item) ;
302
- encode_def_id ( rbml_w, def_id ) ;
303
- match variant. node . kind {
304
- ast :: TupleVariantKind ( _ ) => encode_family ( rbml_w , 'v' ) ,
305
- ast :: StructVariantKind ( _ ) => encode_family ( rbml_w , 'V' )
306
- }
307
- encode_name ( rbml_w, variant. node . name . name ) ;
301
+ encode_def_id ( rbml_w, vid ) ;
302
+ encode_family ( rbml_w , match variant. kind ( ) {
303
+ ty :: VariantKind :: Unit | ty :: VariantKind :: Tuple => 'v' ,
304
+ ty :: VariantKind :: Dict => 'V'
305
+ } ) ;
306
+ encode_name ( rbml_w, variant. name ) ;
308
307
encode_parent_item ( rbml_w, local_def ( id) ) ;
309
- encode_visibility ( rbml_w, variant. node . vis ) ;
310
- encode_attributes ( rbml_w, & variant. node . attrs ) ;
311
- encode_repr_attrs ( rbml_w, ecx, & variant. node . attrs ) ;
308
+ encode_visibility ( rbml_w, vis) ;
309
+
310
+ let attrs = ecx. tcx . get_attrs ( vid) ;
311
+ encode_attributes ( rbml_w, & attrs) ;
312
+ encode_repr_attrs ( rbml_w, ecx, & attrs) ;
312
313
313
- let stab = stability:: lookup ( ecx. tcx , ast_util :: local_def ( variant . node . id ) ) ;
314
+ let stab = stability:: lookup ( ecx. tcx , vid ) ;
314
315
encode_stability ( rbml_w, stab) ;
315
316
316
- match variant. node . kind {
317
- ast:: TupleVariantKind ( _) => { } ,
318
- ast:: StructVariantKind ( _) => {
319
- let fields = ecx. tcx . lookup_struct_fields ( def_id) ;
320
- let idx = encode_info_for_struct ( ecx,
321
- rbml_w,
322
- & fields[ ..] ,
323
- index) ;
324
- encode_struct_fields ( rbml_w, & fields[ ..] , def_id) ;
325
- encode_index ( rbml_w, idx, write_i64) ;
326
- }
317
+ if let ty:: VariantKind :: Dict = variant. kind ( ) {
318
+ let idx = encode_info_for_struct ( ecx,
319
+ rbml_w,
320
+ & variant. fields ,
321
+ index) ;
322
+ encode_index ( rbml_w, idx, write_i64) ;
327
323
}
328
- let specified_disr_val = vi[ i] . disr_val ;
324
+
325
+ encode_struct_fields ( rbml_w, & variant. fields , vid) ;
326
+
327
+ let specified_disr_val = variant. disr_val ;
329
328
if specified_disr_val != disr_val {
330
329
encode_disr_val ( ecx, rbml_w, specified_disr_val) ;
331
330
disr_val = specified_disr_val;
332
331
}
333
- encode_bounds_and_type_for_item ( rbml_w, ecx, def_id . local_id ( ) ) ;
332
+ encode_bounds_and_type_for_item ( rbml_w, ecx, vid . node ) ;
334
333
335
- ecx. tcx . map . with_path ( variant . node . id , |path| encode_path ( rbml_w, path) ) ;
334
+ ecx. tcx . map . with_path ( vid . node , |path| encode_path ( rbml_w, path) ) ;
336
335
rbml_w. end_tag ( ) ;
337
336
disr_val = disr_val. wrapping_add ( 1 ) ;
338
- i += 1 ;
339
337
}
340
338
}
341
339
@@ -630,19 +628,19 @@ fn encode_provided_source(rbml_w: &mut Encoder,
630
628
}
631
629
632
630
/* Returns an index of items in this class */
633
- fn encode_info_for_struct ( ecx : & EncodeContext ,
634
- rbml_w : & mut Encoder ,
635
- fields : & [ ty:: FieldTy ] ,
636
- global_index : & mut Vec < entry < i64 > > )
637
- -> Vec < entry < i64 > > {
631
+ fn encode_info_for_struct < ' a , ' tcx > ( ecx : & EncodeContext < ' a , ' tcx > ,
632
+ rbml_w : & mut Encoder ,
633
+ fields : & [ ty:: FieldDef < ' tcx > ] ,
634
+ global_index : & mut Vec < entry < i64 > > )
635
+ -> Vec < entry < i64 > > {
638
636
/* Each class has its own index, since different classes
639
637
may have fields with the same name */
640
638
let mut index = Vec :: new ( ) ;
641
639
/* We encode both private and public fields -- need to include
642
640
private fields to get the offsets right */
643
641
for field in fields {
644
642
let nm = field. name ;
645
- let id = field. id . node ;
643
+ let id = field. did . node ;
646
644
647
645
let pos = rbml_w. mark_stable_position ( ) ;
648
646
index. push ( entry { val : id as i64 , pos : pos} ) ;
@@ -658,7 +656,7 @@ fn encode_info_for_struct(ecx: &EncodeContext,
658
656
encode_bounds_and_type_for_item ( rbml_w, ecx, id) ;
659
657
encode_def_id ( rbml_w, local_def ( id) ) ;
660
658
661
- let stab = stability:: lookup ( ecx. tcx , field. id ) ;
659
+ let stab = stability:: lookup ( ecx. tcx , field. did ) ;
662
660
encode_stability ( rbml_w, stab) ;
663
661
664
662
rbml_w. end_tag ( ) ;
@@ -1150,20 +1148,18 @@ fn encode_info_for_item(ecx: &EncodeContext,
1150
1148
encode_enum_variant_info ( ecx,
1151
1149
rbml_w,
1152
1150
item. id ,
1153
- & ( * enum_definition ) . variants ,
1151
+ vis ,
1154
1152
index) ;
1155
1153
}
1156
1154
ast:: ItemStruct ( ref struct_def, _) => {
1157
- let fields = tcx. lookup_struct_fields ( def_id) ;
1155
+ let def = ecx. tcx . lookup_adt_def ( def_id) ;
1156
+ let fields = & def. struct_variant ( ) . fields ;
1158
1157
1159
1158
/* First, encode the fields
1160
1159
These come first because we need to write them to make
1161
1160
the index, and the index needs to be in the item for the
1162
1161
class itself */
1163
- let idx = encode_info_for_struct ( ecx,
1164
- rbml_w,
1165
- & fields[ ..] ,
1166
- index) ;
1162
+ let idx = encode_info_for_struct ( ecx, rbml_w, & fields, index) ;
1167
1163
1168
1164
/* Index the class*/
1169
1165
add_to_index ( item, rbml_w, index) ;
@@ -1185,7 +1181,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
1185
1181
/* Encode def_ids for each field and method
1186
1182
for methods, write all the stuff get_trait_method
1187
1183
needs to know*/
1188
- encode_struct_fields ( rbml_w, & fields[ .. ] , def_id) ;
1184
+ encode_struct_fields ( rbml_w, & fields, def_id) ;
1189
1185
1190
1186
encode_inlined_item ( ecx, rbml_w, IIItemRef ( item) ) ;
1191
1187
0 commit comments