@@ -49,6 +49,8 @@ use syntax::diagnostic::span_handler;
49
49
use syntax:: parse:: token:: special_idents;
50
50
use syntax:: print:: pprust;
51
51
use syntax:: { ast_util, visit} ;
52
+ use syntax:: opt_vec:: OptVec ;
53
+ use syntax:: opt_vec;
52
54
use syntax;
53
55
use writer = std:: ebml:: writer;
54
56
@@ -187,10 +189,11 @@ fn encode_ty_type_param_bounds(ebml_w: writer::Encoder, ecx: @EncodeContext,
187
189
}
188
190
}
189
191
190
- fn encode_type_param_bounds ( ebml_w : writer:: Encoder , ecx : @EncodeContext ,
191
- params : & [ ty_param ] ) {
192
+ fn encode_type_param_bounds ( ebml_w : writer:: Encoder ,
193
+ ecx : @EncodeContext ,
194
+ params : & OptVec < TyParam > ) {
192
195
let ty_param_bounds =
193
- @params. map ( |param| ecx. tcx . ty_param_bounds . get ( & param. id ) ) ;
196
+ @params. map_to_vec ( |param| ecx. tcx . ty_param_bounds . get ( & param. id ) ) ;
194
197
encode_ty_type_param_bounds ( ebml_w, ecx, ty_param_bounds) ;
195
198
}
196
199
@@ -265,7 +268,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder,
265
268
id : node_id , variants : & [ variant ] ,
266
269
path : & [ ast_map:: path_elt ] ,
267
270
index : @mut ~[ entry < int > ] ,
268
- ty_params : & [ ty_param ] ) {
271
+ generics : & ast :: Generics ) {
269
272
let mut disr_val = 0 ;
270
273
let mut i = 0 ;
271
274
let vi = ty:: enum_variants ( ecx. tcx ,
@@ -281,7 +284,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder,
281
284
node_id_to_type ( ecx. tcx , variant. node . id ) ) ;
282
285
match variant. node . kind {
283
286
ast:: tuple_variant_kind( ref args)
284
- if args. len ( ) > 0 && ty_params. len ( ) == 0 => {
287
+ if args. len ( ) > 0 && generics . ty_params . len ( ) == 0 => {
285
288
encode_symbol ( ecx, ebml_w, variant. node . id ) ;
286
289
}
287
290
ast:: tuple_variant_kind( _) | ast:: struct_variant_kind( _) |
@@ -292,7 +295,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder,
292
295
encode_disr_val ( ecx, ebml_w, vi[ i] . disr_val ) ;
293
296
disr_val = vi[ i] . disr_val ;
294
297
}
295
- encode_type_param_bounds ( ebml_w, ecx, ty_params) ;
298
+ encode_type_param_bounds ( ebml_w, ecx, & generics . ty_params ) ;
296
299
encode_path ( ecx, ebml_w, path,
297
300
ast_map:: path_name ( variant. node . name ) ) ;
298
301
ebml_w. end_tag ( ) ;
@@ -465,14 +468,18 @@ fn encode_info_for_struct(ecx: @EncodeContext, ebml_w: writer::Encoder,
465
468
}
466
469
467
470
// This is for encoding info for ctors and dtors
468
- fn encode_info_for_ctor ( ecx : @EncodeContext , ebml_w : writer:: Encoder ,
469
- id : node_id , ident : ident , path : & [ ast_map:: path_elt ] ,
470
- item : Option < inlined_item > , tps : & [ ty_param ] ) {
471
+ fn encode_info_for_ctor ( ecx : @EncodeContext ,
472
+ ebml_w : writer:: Encoder ,
473
+ id : node_id ,
474
+ ident : ident ,
475
+ path : & [ ast_map:: path_elt ] ,
476
+ item : Option < inlined_item > ,
477
+ generics : & ast:: Generics ) {
471
478
ebml_w. start_tag ( tag_items_data_item) ;
472
479
encode_name ( ecx, ebml_w, ident) ;
473
480
encode_def_id ( ebml_w, local_def ( id) ) ;
474
481
encode_family ( ebml_w, purity_fn_family ( ast:: impure_fn) ) ;
475
- encode_type_param_bounds ( ebml_w, ecx, tps ) ;
482
+ encode_type_param_bounds ( ebml_w, ecx, & generics . ty_params ) ;
476
483
let its_ty = node_id_to_type ( ecx. tcx , id) ;
477
484
debug ! ( "fn name = %s ty = %s its node id = %d" ,
478
485
* ecx. tcx. sess. str_of( ident) ,
@@ -518,9 +525,12 @@ fn encode_info_for_method(ecx: @EncodeContext,
518
525
should_inline : bool ,
519
526
parent_id : node_id ,
520
527
m : @method ,
521
- +all_tps : ~[ ty_param ] ) {
522
- debug ! ( "encode_info_for_method: %d %s %u" , m. id,
523
- * ecx. tcx. sess. str_of( m. ident) , all_tps. len( ) ) ;
528
+ owner_generics : & ast:: Generics ,
529
+ method_generics : & ast:: Generics ) {
530
+ debug ! ( "encode_info_for_method: %d %s %u %u" , m. id,
531
+ * ecx. tcx. sess. str_of( m. ident) ,
532
+ owner_generics. ty_params. len( ) ,
533
+ method_generics. ty_params. len( ) ) ;
524
534
ebml_w. start_tag ( tag_items_data_item) ;
525
535
encode_def_id ( ebml_w, local_def ( m. id ) ) ;
526
536
match m. self_ty . node {
@@ -529,8 +539,13 @@ fn encode_info_for_method(ecx: @EncodeContext,
529
539
}
530
540
_ => encode_family ( ebml_w, purity_fn_family ( m. purity ) )
531
541
}
532
- let len = all_tps. len ( ) ;
533
- encode_type_param_bounds ( ebml_w, ecx, all_tps) ;
542
+
543
+ let mut combined_ty_params = opt_vec:: Empty ;
544
+ combined_ty_params. push_all ( & owner_generics. ty_params ) ;
545
+ combined_ty_params. push_all ( & method_generics. ty_params ) ;
546
+ let len = combined_ty_params. len ( ) ;
547
+ encode_type_param_bounds ( ebml_w, ecx, & combined_ty_params) ;
548
+
534
549
encode_type ( ecx, ebml_w, node_id_to_type ( ecx. tcx , m. id ) ) ;
535
550
encode_name ( ecx, ebml_w, m. ident ) ;
536
551
encode_path ( ecx, ebml_w, impl_path, ast_map:: path_name ( m. ident ) ) ;
@@ -604,13 +619,13 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
604
619
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
605
620
ebml_w.end_tag();
606
621
}
607
- item_fn(_, purity, tps , _) => {
622
+ item_fn(_, purity, ref generics , _) => {
608
623
add_to_index();
609
624
ebml_w.start_tag(tag_items_data_item);
610
625
encode_def_id(ebml_w, local_def(item.id));
611
626
encode_family(ebml_w, purity_fn_family(purity));
612
- let tps_len = tps .len();
613
- encode_type_param_bounds(ebml_w, ecx, tps );
627
+ let tps_len = generics.ty_params .len();
628
+ encode_type_param_bounds(ebml_w, ecx, &generics.ty_params );
614
629
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
615
630
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
616
631
encode_attributes(ebml_w, item.attrs);
@@ -634,24 +649,24 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
634
649
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
635
650
ebml_w.end_tag();
636
651
}
637
- item_ty(_, tps ) => {
652
+ item_ty(_, ref generics ) => {
638
653
add_to_index();
639
654
ebml_w.start_tag(tag_items_data_item);
640
655
encode_def_id(ebml_w, local_def(item.id));
641
656
encode_family(ebml_w, 'y');
642
- encode_type_param_bounds(ebml_w, ecx, tps );
657
+ encode_type_param_bounds(ebml_w, ecx, &generics.ty_params );
643
658
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
644
659
encode_name(ecx, ebml_w, item.ident);
645
660
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
646
661
encode_region_param(ecx, ebml_w, item);
647
662
ebml_w.end_tag();
648
663
}
649
- item_enum(ref enum_definition, ref tps ) => {
664
+ item_enum(ref enum_definition, ref generics ) => {
650
665
add_to_index();
651
666
do ebml_w.wr_tag(tag_items_data_item) {
652
667
encode_def_id(ebml_w, local_def(item.id));
653
668
encode_family(ebml_w, 't');
654
- encode_type_param_bounds(ebml_w, ecx, *tps );
669
+ encode_type_param_bounds(ebml_w, ecx, &generics.ty_params );
655
670
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
656
671
encode_name(ecx, ebml_w, item.ident);
657
672
for (*enum_definition).variants.each |v| {
@@ -667,9 +682,9 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
667
682
(*enum_definition).variants,
668
683
path,
669
684
index,
670
- *tps );
685
+ generics );
671
686
}
672
- item_struct(struct_def, tps ) => {
687
+ item_struct(struct_def, ref generics ) => {
673
688
/* First, encode the fields
674
689
These come first because we need to write them to make
675
690
the index, and the index needs to be in the item for the
@@ -686,24 +701,25 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
686
701
*ecx.tcx.sess.str_of(item.ident) +
687
702
~" _dtor"),
688
703
path,
689
- if tps .len() > 0u {
704
+ if generics.ty_params .len() > 0u {
690
705
Some(ii_dtor(copy *dtor,
691
706
item.ident,
692
- copy tps ,
707
+ copy *generics ,
693
708
local_def(item.id))) }
694
709
else {
695
710
None
696
711
},
697
- tps );
712
+ generics );
698
713
}
699
714
700
715
/* Index the class*/
701
716
add_to_index();
717
+
702
718
/* Now, make an item for the class itself */
703
719
ebml_w.start_tag(tag_items_data_item);
704
720
encode_def_id(ebml_w, local_def(item.id));
705
721
encode_family(ebml_w, 'S');
706
- encode_type_param_bounds(ebml_w, ecx, tps );
722
+ encode_type_param_bounds(ebml_w, ecx, &generics.ty_params );
707
723
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
708
724
709
725
// If this is a tuple- or enum-like struct, encode the type of the
@@ -759,13 +775,13 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
759
775
encode_index(ebml_w, bkts, write_int);
760
776
ebml_w.end_tag();
761
777
}
762
- item_impl(tps , opt_trait, ty, methods) => {
778
+ item_impl(ref generics , opt_trait, ty, ref methods) => {
763
779
add_to_index();
764
780
ebml_w.start_tag(tag_items_data_item);
765
781
encode_def_id(ebml_w, local_def(item.id));
766
782
encode_family(ebml_w, 'i');
767
783
encode_region_param(ecx, ebml_w, item);
768
- encode_type_param_bounds(ebml_w, ecx, tps );
784
+ encode_type_param_bounds(ebml_w, ecx, &generics.ty_params );
769
785
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
770
786
encode_name(ecx, ebml_w, item.ident);
771
787
encode_attributes(ebml_w, item.attrs);
@@ -797,18 +813,18 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
797
813
encode_info_for_method(ecx, ebml_w, impl_path,
798
814
should_inline(m.attrs),
799
815
item.id, *m,
800
- vec::append(/*bad*/copy tps, m.tps) );
816
+ generics, &m.generics );
801
817
}
802
818
}
803
- item_trait(ref tps , ref traits, ref ms) => {
819
+ item_trait(ref generics , ref traits, ref ms) => {
804
820
let provided_methods = dvec::DVec();
805
821
806
822
add_to_index();
807
823
ebml_w.start_tag(tag_items_data_item);
808
824
encode_def_id(ebml_w, local_def(item.id));
809
825
encode_family(ebml_w, 'I');
810
826
encode_region_param(ecx, ebml_w, item);
811
- encode_type_param_bounds(ebml_w, ecx, *tps );
827
+ encode_type_param_bounds(ebml_w, ecx, &generics.ty_params );
812
828
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
813
829
encode_name(ecx, ebml_w, item.ident);
814
830
encode_attributes(ebml_w, item.attrs);
@@ -820,7 +836,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
820
836
encode_def_id(ebml_w, local_def((*ty_m).id));
821
837
encode_name(ecx, ebml_w, mty.ident);
822
838
encode_type_param_bounds(ebml_w, ecx,
823
- (* ty_m).tps );
839
+ & ty_m.generics.ty_params );
824
840
encode_type(ecx, ebml_w,
825
841
ty::mk_bare_fn(tcx, copy mty.fty));
826
842
encode_family(ebml_w, purity_fn_family(mty.fty.purity));
@@ -834,7 +850,8 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
834
850
ebml_w.start_tag(tag_item_trait_method);
835
851
encode_def_id(ebml_w, local_def(m.id));
836
852
encode_name(ecx, ebml_w, mty.ident);
837
- encode_type_param_bounds(ebml_w, ecx, m.tps);
853
+ encode_type_param_bounds(ebml_w, ecx,
854
+ &m.generics.ty_params);
838
855
encode_type(ecx, ebml_w,
839
856
ty::mk_bare_fn(tcx, copy mty.fty));
840
857
encode_family(ebml_w, purity_fn_family(mty.fty.purity));
@@ -880,8 +897,14 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
880
897
// Finally, output all the provided methods as items.
881
898
for provided_methods.each |m| {
882
899
index.push(entry { val: m.id, pos: ebml_w.writer.tell() });
900
+
901
+ // We do not concatenate the generics of the owning impl and that
902
+ // of provided methods. I am not sure why this is. -ndm
903
+ let owner_generics = ast_util::empty_generics();
904
+
883
905
encode_info_for_method(ecx, ebml_w, /*bad*/copy path,
884
- true, item.id, *m, /*bad*/copy m.tps);
906
+ true, item.id, *m,
907
+ &owner_generics, &m.generics);
885
908
}
886
909
}
887
910
item_mac(*) => fail!(~" item macros unimplemented")
@@ -898,11 +921,11 @@ fn encode_info_for_foreign_item(ecx: @EncodeContext,
898
921
index.push(entry { val: nitem.id, pos: ebml_w.writer.tell() });
899
922
900
923
ebml_w.start_tag(tag_items_data_item);
901
- match /*bad*/copy nitem.node {
902
- foreign_item_fn(_, purity, tps ) => {
924
+ match nitem.node {
925
+ foreign_item_fn(_, purity, ref generics ) => {
903
926
encode_def_id(ebml_w, local_def(nitem.id));
904
927
encode_family(ebml_w, purity_fn_family(purity));
905
- encode_type_param_bounds(ebml_w, ecx, tps );
928
+ encode_type_param_bounds(ebml_w, ecx, &generics.ty_params );
906
929
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id));
907
930
if abi == foreign_abi_rust_intrinsic {
908
931
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_foreign(nitem));
0 commit comments