@@ -29,7 +29,7 @@ use middle::check_const::ConstQualif;
29
29
use middle:: privacy:: { AllPublic , LastMod } ;
30
30
use middle:: subst;
31
31
use middle:: subst:: VecPerParamSpace ;
32
- use middle:: ty:: { self , Ty , MethodCall , MethodCallee , MethodOrigin } ;
32
+ use middle:: ty:: { self , Ty } ;
33
33
34
34
use syntax:: { ast, ast_util, codemap, fold} ;
35
35
use syntax:: codemap:: Span ;
@@ -600,48 +600,54 @@ impl tr for ty::UpvarCapture {
600
600
601
601
trait read_method_callee_helper < ' tcx > {
602
602
fn read_method_callee < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
603
- -> ( u32 , MethodCallee < ' tcx > ) ;
603
+ -> ( u32 , ty :: MethodCallee < ' tcx > ) ;
604
604
}
605
605
606
606
fn encode_method_callee < ' a , ' tcx > ( ecx : & e:: EncodeContext < ' a , ' tcx > ,
607
607
rbml_w : & mut Encoder ,
608
608
autoderef : u32 ,
609
- method : & MethodCallee < ' tcx > ) {
609
+ method : & ty :: MethodCallee < ' tcx > ) {
610
610
use serialize:: Encoder ;
611
611
612
- rbml_w. emit_struct ( "MethodCallee" , 4 , |rbml_w| {
612
+ rbml_w. emit_struct ( "MethodCallee" , 5 , |rbml_w| {
613
613
rbml_w. emit_struct_field ( "autoderef" , 0 , |rbml_w| {
614
614
autoderef. encode ( rbml_w)
615
615
} ) ;
616
- rbml_w. emit_struct_field ( "origin " , 1 , |rbml_w| {
617
- Ok ( rbml_w. emit_method_origin ( ecx , & method. origin ) )
616
+ rbml_w. emit_struct_field ( "def_id " , 1 , |rbml_w| {
617
+ Ok ( rbml_w. emit_def_id ( method. def_id ) )
618
618
} ) ;
619
- rbml_w. emit_struct_field ( "ty" , 2 , |rbml_w| {
619
+ rbml_w. emit_struct_field ( "origin" , 2 , |rbml_w| {
620
+ Ok ( rbml_w. emit_method_origin ( method. origin ) )
621
+ } ) ;
622
+ rbml_w. emit_struct_field ( "ty" , 3 , |rbml_w| {
620
623
Ok ( rbml_w. emit_ty ( ecx, method. ty ) )
621
624
} ) ;
622
- rbml_w. emit_struct_field ( "substs" , 3 , |rbml_w| {
625
+ rbml_w. emit_struct_field ( "substs" , 4 , |rbml_w| {
623
626
Ok ( rbml_w. emit_substs ( ecx, & method. substs ) )
624
627
} )
625
628
} ) . unwrap ( ) ;
626
629
}
627
630
628
631
impl < ' a , ' tcx > read_method_callee_helper < ' tcx > for reader:: Decoder < ' a > {
629
632
fn read_method_callee < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
630
- -> ( u32 , MethodCallee < ' tcx > ) {
633
+ -> ( u32 , ty :: MethodCallee < ' tcx > ) {
631
634
632
- self . read_struct ( "MethodCallee" , 4 , |this| {
635
+ self . read_struct ( "MethodCallee" , 5 , |this| {
633
636
let autoderef = this. read_struct_field ( "autoderef" , 0 , |this| {
634
637
Decodable :: decode ( this)
635
638
} ) . unwrap ( ) ;
636
- Ok ( ( autoderef, MethodCallee {
637
- origin : this. read_struct_field ( "origin" , 1 , |this| {
639
+ Ok ( ( autoderef, ty:: MethodCallee {
640
+ def_id : this. read_struct_field ( "def_id" , 1 , |this| {
641
+ Ok ( this. read_def_id ( dcx) )
642
+ } ) . unwrap ( ) ,
643
+ origin : this. read_struct_field ( "origin" , 2 , |this| {
638
644
Ok ( this. read_method_origin ( dcx) )
639
645
} ) . unwrap ( ) ,
640
- ty : this. read_struct_field ( "ty" , 2 , |this| {
646
+ ty : this. read_struct_field ( "ty" , 3 , |this| {
641
647
Ok ( this. read_ty ( dcx) )
642
648
} ) . unwrap ( ) ,
643
- substs : this. read_struct_field ( "substs" , 3 , |this| {
644
- Ok ( this. read_substs ( dcx) )
649
+ substs : this. read_struct_field ( "substs" , 4 , |this| {
650
+ Ok ( dcx . tcx . mk_substs ( this. read_substs ( dcx) ) )
645
651
} ) . unwrap ( )
646
652
} ) )
647
653
} ) . unwrap ( )
@@ -707,9 +713,7 @@ impl<'a, 'tcx> get_ty_str_ctxt<'tcx> for e::EncodeContext<'a, 'tcx> {
707
713
trait rbml_writer_helpers < ' tcx > {
708
714
fn emit_closure_type < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
709
715
closure_type : & ty:: ClosureTy < ' tcx > ) ;
710
- fn emit_method_origin < ' a > ( & mut self ,
711
- ecx : & e:: EncodeContext < ' a , ' tcx > ,
712
- method_origin : & ty:: MethodOrigin < ' tcx > ) ;
716
+ fn emit_method_origin ( & mut self , method_origin : ty:: MethodOrigin ) ;
713
717
fn emit_ty < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > , ty : Ty < ' tcx > ) ;
714
718
fn emit_tys < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > , tys : & [ Ty < ' tcx > ] ) ;
715
719
fn emit_type_param_def < ' a > ( & mut self , ecx : & e:: EncodeContext < ' a , ' tcx > ,
@@ -741,61 +745,31 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
741
745
} ) ;
742
746
}
743
747
744
- fn emit_method_origin < ' b > ( & mut self ,
745
- ecx : & e:: EncodeContext < ' b , ' tcx > ,
746
- method_origin : & ty:: MethodOrigin < ' tcx > )
747
- {
748
+ fn emit_method_origin ( & mut self , method_origin : ty:: MethodOrigin ) {
748
749
use serialize:: Encoder ;
749
750
750
751
self . emit_enum ( "MethodOrigin" , |this| {
751
- match * method_origin {
752
- ty:: MethodStatic ( def_id) => {
753
- this. emit_enum_variant ( "MethodStatic" , 0 , 1 , |this| {
754
- Ok ( this. emit_def_id ( def_id) )
755
- } )
752
+ match method_origin {
753
+ ty:: MethodOrigin :: Inherent => {
754
+ this. emit_enum_variant ( "Inherent" , 0 , 0 , |_| Ok ( ( ) ) )
756
755
}
757
756
758
- ty:: MethodTypeParam ( ref p) => {
759
- this. emit_enum_variant ( "MethodTypeParam" , 1 , 1 , |this| {
760
- this. emit_struct ( "MethodParam" , 2 , |this| {
761
- try!( this. emit_struct_field ( "trait_ref" , 0 , |this| {
762
- Ok ( this. emit_trait_ref ( ecx, & p. trait_ref ) )
763
- } ) ) ;
764
- try!( this. emit_struct_field ( "method_num" , 0 , |this| {
765
- this. emit_uint ( p. method_num )
766
- } ) ) ;
767
- try!( this. emit_struct_field ( "impl_def_id" , 0 , |this| {
768
- this. emit_option ( |this| {
769
- match p. impl_def_id {
770
- None => this. emit_option_none ( ) ,
771
- Some ( did) => this. emit_option_some ( |this| {
772
- Ok ( this. emit_def_id ( did) )
773
- } )
774
- }
757
+ ty:: MethodOrigin :: Trait ( impl_def_id) => {
758
+ this. emit_enum_variant ( "Trait" , 1 , 1 , |this| {
759
+ this. emit_option ( |this| {
760
+ match impl_def_id {
761
+ None => this. emit_option_none ( ) ,
762
+ Some ( did) => this. emit_option_some ( |this| {
763
+ Ok ( this. emit_def_id ( did) )
775
764
} )
776
- } ) ) ;
777
- Ok ( ( ) )
765
+ }
778
766
} )
779
767
} )
780
768
}
781
769
782
- ty:: MethodTraitObject ( ref o) => {
783
- this. emit_enum_variant ( "MethodTraitObject" , 2 , 1 , |this| {
784
- this. emit_struct ( "MethodObject" , 2 , |this| {
785
- try!( this. emit_struct_field ( "trait_ref" , 0 , |this| {
786
- Ok ( this. emit_trait_ref ( ecx, & o. trait_ref ) )
787
- } ) ) ;
788
- try!( this. emit_struct_field ( "object_trait_id" , 0 , |this| {
789
- Ok ( this. emit_def_id ( o. object_trait_id ) )
790
- } ) ) ;
791
- try!( this. emit_struct_field ( "method_num" , 0 , |this| {
792
- this. emit_uint ( o. method_num )
793
- } ) ) ;
794
- try!( this. emit_struct_field ( "vtable_index" , 0 , |this| {
795
- this. emit_uint ( o. vtable_index )
796
- } ) ) ;
797
- Ok ( ( ) )
798
- } )
770
+ ty:: MethodOrigin :: Object ( vtable_index) => {
771
+ this. emit_enum_variant ( "Object" , 2 , 1 , |this| {
772
+ this. emit_uint ( vtable_index)
799
773
} )
800
774
}
801
775
}
@@ -1071,7 +1045,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
1071
1045
} )
1072
1046
}
1073
1047
1074
- let method_call = MethodCall :: expr ( id) ;
1048
+ let method_call = ty :: MethodCall :: expr ( id) ;
1075
1049
if let Some ( method) = tcx. tables . borrow ( ) . method_map . get ( & method_call) {
1076
1050
rbml_w. tag ( c:: tag_table_method_map, |rbml_w| {
1077
1051
rbml_w. id ( id) ;
@@ -1083,7 +1057,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
1083
1057
match * adjustment {
1084
1058
ty:: AdjustDerefRef ( ref adj) => {
1085
1059
for autoderef in 0 ..adj. autoderefs {
1086
- let method_call = MethodCall :: autoderef ( id, autoderef as u32 ) ;
1060
+ let method_call = ty :: MethodCall :: autoderef ( id, autoderef as u32 ) ;
1087
1061
if let Some ( method) = tcx. tables . borrow ( ) . method_map . get ( & method_call) {
1088
1062
rbml_w. tag ( c:: tag_table_method_map, |rbml_w| {
1089
1063
rbml_w. id ( id) ;
@@ -1144,8 +1118,7 @@ impl<'a> doc_decoder_helpers for rbml::Doc<'a> {
1144
1118
}
1145
1119
1146
1120
trait rbml_decoder_decoder_helpers < ' tcx > {
1147
- fn read_method_origin < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
1148
- -> ty:: MethodOrigin < ' tcx > ;
1121
+ fn read_method_origin ( & mut self , dcx : & DecodeContext ) -> ty:: MethodOrigin ;
1149
1122
fn read_ty < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > ) -> Ty < ' tcx > ;
1150
1123
fn read_tys < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > ) -> Vec < Ty < ' tcx > > ;
1151
1124
fn read_trait_ref < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
@@ -1229,77 +1202,25 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
1229
1202
} ) . unwrap ( )
1230
1203
}
1231
1204
1232
- fn read_method_origin < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1233
- -> ty:: MethodOrigin < ' tcx >
1234
- {
1205
+ fn read_method_origin ( & mut self , dcx : & DecodeContext ) -> ty:: MethodOrigin {
1235
1206
self . read_enum ( "MethodOrigin" , |this| {
1236
- let variants = & [ "MethodStatic " , "MethodTypeParam " , "MethodTraitObject " ] ;
1207
+ let variants = & [ "Inherent " , "Trait " , "Object " ] ;
1237
1208
this. read_enum_variant ( variants, |this, i| {
1238
- Ok ( match i {
1239
- 0 => {
1240
- let def_id = this. read_def_id ( dcx) ;
1241
- ty:: MethodStatic ( def_id)
1242
- }
1209
+ match i {
1210
+ 0 => Ok ( ty:: MethodOrigin :: Inherent ) ,
1243
1211
1244
- 1 => {
1245
- this. read_struct ( "MethodTypeParam" , 2 , |this| {
1246
- Ok ( ty:: MethodTypeParam (
1247
- ty:: MethodParam {
1248
- trait_ref : {
1249
- this. read_struct_field ( "trait_ref" , 0 , |this| {
1250
- Ok ( this. read_trait_ref ( dcx) )
1251
- } ) . unwrap ( )
1252
- } ,
1253
- method_num : {
1254
- this. read_struct_field ( "method_num" , 1 , |this| {
1255
- this. read_uint ( )
1256
- } ) . unwrap ( )
1257
- } ,
1258
- impl_def_id : {
1259
- this. read_struct_field ( "impl_def_id" , 2 , |this| {
1260
- this. read_option ( |this, b| {
1261
- if b {
1262
- Ok ( Some ( this. read_def_id ( dcx) ) )
1263
- } else {
1264
- Ok ( None )
1265
- }
1266
- } )
1267
- } ) . unwrap ( )
1268
- }
1269
- } ) )
1270
- } ) . unwrap ( )
1271
- }
1212
+ 1 => this. read_option ( |this, b| {
1213
+ Ok ( ty:: MethodOrigin :: Trait ( if b {
1214
+ Some ( this. read_def_id ( dcx) )
1215
+ } else {
1216
+ None
1217
+ } ) )
1218
+ } ) ,
1272
1219
1273
- 2 => {
1274
- this. read_struct ( "MethodTraitObject" , 2 , |this| {
1275
- Ok ( ty:: MethodTraitObject (
1276
- ty:: MethodObject {
1277
- trait_ref : {
1278
- this. read_struct_field ( "trait_ref" , 0 , |this| {
1279
- Ok ( this. read_trait_ref ( dcx) )
1280
- } ) . unwrap ( )
1281
- } ,
1282
- object_trait_id : {
1283
- this. read_struct_field ( "object_trait_id" , 1 , |this| {
1284
- Ok ( this. read_def_id ( dcx) )
1285
- } ) . unwrap ( )
1286
- } ,
1287
- method_num : {
1288
- this. read_struct_field ( "method_num" , 2 , |this| {
1289
- this. read_uint ( )
1290
- } ) . unwrap ( )
1291
- } ,
1292
- vtable_index : {
1293
- this. read_struct_field ( "vtable_index" , 3 , |this| {
1294
- this. read_uint ( )
1295
- } ) . unwrap ( )
1296
- } ,
1297
- } ) )
1298
- } ) . unwrap ( )
1299
- }
1220
+ 2 => this. read_uint ( ) . map ( |idx| ty:: MethodOrigin :: Object ( idx) ) ,
1300
1221
1301
1222
_ => panic ! ( ".." )
1302
- } )
1223
+ }
1303
1224
} )
1304
1225
} ) . unwrap ( )
1305
1226
}
@@ -1651,7 +1572,7 @@ fn decode_side_tables(dcx: &DecodeContext,
1651
1572
}
1652
1573
c:: tag_table_method_map => {
1653
1574
let ( autoderef, method) = val_dsr. read_method_callee ( dcx) ;
1654
- let method_call = MethodCall {
1575
+ let method_call = ty :: MethodCall {
1655
1576
expr_id : id,
1656
1577
autoderef : autoderef
1657
1578
} ;
0 commit comments