@@ -856,7 +856,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
856856 ty:: EarlyBinder ( & * output)
857857 }
858858
859- fn get_variant ( self , kind : & DefKind , index : DefIndex , parent_did : DefId ) -> ty:: VariantDef {
859+ fn get_variant (
860+ self ,
861+ kind : DefKind ,
862+ index : DefIndex ,
863+ parent_did : DefId ,
864+ ) -> ( VariantIdx , ty:: VariantDef ) {
860865 let adt_kind = match kind {
861866 DefKind :: Variant => ty:: AdtKind :: Enum ,
862867 DefKind :: Struct => ty:: AdtKind :: Struct ,
@@ -870,22 +875,25 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
870875 if adt_kind == ty:: AdtKind :: Enum { Some ( self . local_def_id ( index) ) } else { None } ;
871876 let ctor = data. ctor . map ( |( kind, index) | ( kind, self . local_def_id ( index) ) ) ;
872877
873- ty:: VariantDef :: new (
874- self . item_name ( index) ,
875- variant_did,
876- ctor,
877- data. discr ,
878- self . get_associated_item_or_field_def_ids ( index)
879- . map ( |did| ty:: FieldDef {
880- did,
881- name : self . item_name ( did. index ) ,
882- vis : self . get_visibility ( did. index ) ,
883- } )
884- . collect ( ) ,
885- adt_kind,
886- parent_did,
887- false ,
888- data. is_non_exhaustive ,
878+ (
879+ data. idx ,
880+ ty:: VariantDef :: new (
881+ self . item_name ( index) ,
882+ variant_did,
883+ ctor,
884+ data. discr ,
885+ self . get_associated_item_or_field_def_ids ( index)
886+ . map ( |did| ty:: FieldDef {
887+ did,
888+ name : self . item_name ( did. index ) ,
889+ vis : self . get_visibility ( did. index ) ,
890+ } )
891+ . collect ( ) ,
892+ adt_kind,
893+ parent_did,
894+ false ,
895+ data. is_non_exhaustive ,
896+ ) ,
889897 )
890898 }
891899
@@ -901,7 +909,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
901909 } ;
902910 let repr = self . root . tables . repr_options . get ( self , item_id) . unwrap ( ) . decode ( self ) ;
903911
904- let variants = if let ty:: AdtKind :: Enum = adt_kind {
912+ let mut variants: Vec < _ > = if let ty:: AdtKind :: Enum = adt_kind {
905913 self . root
906914 . tables
907915 . module_children_non_reexports
@@ -912,15 +920,22 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
912920 let kind = self . def_kind ( index) ;
913921 match kind {
914922 DefKind :: Ctor ( ..) => None ,
915- _ => Some ( self . get_variant ( & kind, index, did) ) ,
923+ _ => Some ( self . get_variant ( kind, index, did) ) ,
916924 }
917925 } )
918926 . collect ( )
919927 } else {
920- std:: iter:: once ( self . get_variant ( & kind, item_id, did) ) . collect ( )
928+ std:: iter:: once ( self . get_variant ( kind, item_id, did) ) . collect ( )
921929 } ;
922930
923- tcx. mk_adt_def ( did, adt_kind, variants, repr)
931+ variants. sort_by_key ( |( idx, _) | * idx) ;
932+
933+ tcx. mk_adt_def (
934+ did,
935+ adt_kind,
936+ variants. into_iter ( ) . map ( |( _, variant) | variant) . collect ( ) ,
937+ repr,
938+ )
924939 }
925940
926941 fn get_visibility ( self , id : DefIndex ) -> Visibility < DefId > {
0 commit comments