@@ -49,6 +49,8 @@ use syntax::diagnostic::span_handler;
4949use syntax:: parse:: token:: special_idents;
5050use syntax:: print:: pprust;
5151use syntax:: { ast_util, visit} ;
52+ use syntax:: opt_vec:: OptVec ;
53+ use syntax:: opt_vec;
5254use syntax;
5355use writer = std:: ebml:: writer;
5456
@@ -187,10 +189,11 @@ fn encode_ty_type_param_bounds(ebml_w: writer::Encoder, ecx: @EncodeContext,
187189 }
188190}
189191
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 > ) {
192195 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 ) ) ;
194197 encode_ty_type_param_bounds ( ebml_w, ecx, ty_param_bounds) ;
195198}
196199
@@ -265,7 +268,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder,
265268 id : node_id , variants : & [ variant ] ,
266269 path : & [ ast_map:: path_elt ] ,
267270 index : @mut ~[ entry < int > ] ,
268- ty_params : & [ ty_param ] ) {
271+ generics : & ast :: Generics ) {
269272 let mut disr_val = 0 ;
270273 let mut i = 0 ;
271274 let vi = ty:: enum_variants ( ecx. tcx ,
@@ -281,7 +284,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder,
281284 node_id_to_type ( ecx. tcx , variant. node . id ) ) ;
282285 match variant. node . kind {
283286 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 => {
285288 encode_symbol ( ecx, ebml_w, variant. node . id ) ;
286289 }
287290 ast:: tuple_variant_kind( _) | ast:: struct_variant_kind( _) |
@@ -292,7 +295,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder,
292295 encode_disr_val ( ecx, ebml_w, vi[ i] . disr_val ) ;
293296 disr_val = vi[ i] . disr_val ;
294297 }
295- encode_type_param_bounds ( ebml_w, ecx, ty_params) ;
298+ encode_type_param_bounds ( ebml_w, ecx, & generics . ty_params ) ;
296299 encode_path ( ecx, ebml_w, path,
297300 ast_map:: path_name ( variant. node . name ) ) ;
298301 ebml_w. end_tag ( ) ;
@@ -465,14 +468,18 @@ fn encode_info_for_struct(ecx: @EncodeContext, ebml_w: writer::Encoder,
465468}
466469
467470// 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 ) {
471478 ebml_w. start_tag ( tag_items_data_item) ;
472479 encode_name ( ecx, ebml_w, ident) ;
473480 encode_def_id ( ebml_w, local_def ( id) ) ;
474481 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 ) ;
476483 let its_ty = node_id_to_type ( ecx. tcx , id) ;
477484 debug ! ( "fn name = %s ty = %s its node id = %d" ,
478485 * ecx. tcx. sess. str_of( ident) ,
@@ -518,9 +525,12 @@ fn encode_info_for_method(ecx: @EncodeContext,
518525 should_inline : bool ,
519526 parent_id : node_id ,
520527 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( ) ) ;
524534 ebml_w. start_tag ( tag_items_data_item) ;
525535 encode_def_id ( ebml_w, local_def ( m. id ) ) ;
526536 match m. self_ty . node {
@@ -529,8 +539,13 @@ fn encode_info_for_method(ecx: @EncodeContext,
529539 }
530540 _ => encode_family ( ebml_w, purity_fn_family ( m. purity ) )
531541 }
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+
534549 encode_type ( ecx, ebml_w, node_id_to_type ( ecx. tcx , m. id ) ) ;
535550 encode_name ( ecx, ebml_w, m. ident ) ;
536551 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,
604619 encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
605620 ebml_w.end_tag();
606621 }
607- item_fn(_, purity, tps , _) => {
622+ item_fn(_, purity, ref generics , _) => {
608623 add_to_index();
609624 ebml_w.start_tag(tag_items_data_item);
610625 encode_def_id(ebml_w, local_def(item.id));
611626 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 );
614629 encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
615630 encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
616631 encode_attributes(ebml_w, item.attrs);
@@ -634,24 +649,24 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
634649 encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
635650 ebml_w.end_tag();
636651 }
637- item_ty(_, tps ) => {
652+ item_ty(_, ref generics ) => {
638653 add_to_index();
639654 ebml_w.start_tag(tag_items_data_item);
640655 encode_def_id(ebml_w, local_def(item.id));
641656 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 );
643658 encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
644659 encode_name(ecx, ebml_w, item.ident);
645660 encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
646661 encode_region_param(ecx, ebml_w, item);
647662 ebml_w.end_tag();
648663 }
649- item_enum(ref enum_definition, ref tps ) => {
664+ item_enum(ref enum_definition, ref generics ) => {
650665 add_to_index();
651666 do ebml_w.wr_tag(tag_items_data_item) {
652667 encode_def_id(ebml_w, local_def(item.id));
653668 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 );
655670 encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
656671 encode_name(ecx, ebml_w, item.ident);
657672 for (*enum_definition).variants.each |v| {
@@ -667,9 +682,9 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
667682 (*enum_definition).variants,
668683 path,
669684 index,
670- *tps );
685+ generics );
671686 }
672- item_struct(struct_def, tps ) => {
687+ item_struct(struct_def, ref generics ) => {
673688 /* First, encode the fields
674689 These come first because we need to write them to make
675690 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,
686701 *ecx.tcx.sess.str_of(item.ident) +
687702 ~" _dtor"),
688703 path,
689- if tps .len() > 0u {
704+ if generics.ty_params .len() > 0u {
690705 Some(ii_dtor(copy *dtor,
691706 item.ident,
692- copy tps ,
707+ copy *generics ,
693708 local_def(item.id))) }
694709 else {
695710 None
696711 },
697- tps );
712+ generics );
698713 }
699714
700715 /* Index the class*/
701716 add_to_index();
717+
702718 /* Now, make an item for the class itself */
703719 ebml_w.start_tag(tag_items_data_item);
704720 encode_def_id(ebml_w, local_def(item.id));
705721 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 );
707723 encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
708724
709725 // 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,
759775 encode_index(ebml_w, bkts, write_int);
760776 ebml_w.end_tag();
761777 }
762- item_impl(tps , opt_trait, ty, methods) => {
778+ item_impl(ref generics , opt_trait, ty, ref methods) => {
763779 add_to_index();
764780 ebml_w.start_tag(tag_items_data_item);
765781 encode_def_id(ebml_w, local_def(item.id));
766782 encode_family(ebml_w, 'i');
767783 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 );
769785 encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
770786 encode_name(ecx, ebml_w, item.ident);
771787 encode_attributes(ebml_w, item.attrs);
@@ -797,18 +813,18 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
797813 encode_info_for_method(ecx, ebml_w, impl_path,
798814 should_inline(m.attrs),
799815 item.id, *m,
800- vec::append(/*bad*/copy tps, m.tps) );
816+ generics, &m.generics );
801817 }
802818 }
803- item_trait(ref tps , ref traits, ref ms) => {
819+ item_trait(ref generics , ref traits, ref ms) => {
804820 let provided_methods = dvec::DVec();
805821
806822 add_to_index();
807823 ebml_w.start_tag(tag_items_data_item);
808824 encode_def_id(ebml_w, local_def(item.id));
809825 encode_family(ebml_w, 'I');
810826 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 );
812828 encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
813829 encode_name(ecx, ebml_w, item.ident);
814830 encode_attributes(ebml_w, item.attrs);
@@ -820,7 +836,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
820836 encode_def_id(ebml_w, local_def((*ty_m).id));
821837 encode_name(ecx, ebml_w, mty.ident);
822838 encode_type_param_bounds(ebml_w, ecx,
823- (* ty_m).tps );
839+ & ty_m.generics.ty_params );
824840 encode_type(ecx, ebml_w,
825841 ty::mk_bare_fn(tcx, copy mty.fty));
826842 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,
834850 ebml_w.start_tag(tag_item_trait_method);
835851 encode_def_id(ebml_w, local_def(m.id));
836852 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);
838855 encode_type(ecx, ebml_w,
839856 ty::mk_bare_fn(tcx, copy mty.fty));
840857 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,
880897 // Finally, output all the provided methods as items.
881898 for provided_methods.each |m| {
882899 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+
883905 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);
885908 }
886909 }
887910 item_mac(*) => fail!(~" item macros unimplemented")
@@ -898,11 +921,11 @@ fn encode_info_for_foreign_item(ecx: @EncodeContext,
898921 index.push(entry { val: nitem.id, pos: ebml_w.writer.tell() });
899922
900923 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 ) => {
903926 encode_def_id(ebml_w, local_def(nitem.id));
904927 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 );
906929 encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id));
907930 if abi == foreign_abi_rust_intrinsic {
908931 (ecx.encode_inlined_item)(ecx, ebml_w, path, ii_foreign(nitem));
0 commit comments