@@ -857,7 +857,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
857857 )
858858 }
859859
860- fn get_variant ( self , kind : & DefKind , index : DefIndex , parent_did : DefId ) -> ty:: VariantDef {
860+ fn get_variant (
861+ self ,
862+ kind : DefKind ,
863+ index : DefIndex ,
864+ parent_did : DefId ,
865+ ) -> ( VariantIdx , ty:: VariantDef ) {
861866 let adt_kind = match kind {
862867 DefKind :: Variant => ty:: AdtKind :: Enum ,
863868 DefKind :: Struct => ty:: AdtKind :: Struct ,
@@ -871,27 +876,30 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
871876 if adt_kind == ty:: AdtKind :: Enum { Some ( self . local_def_id ( index) ) } else { None } ;
872877 let ctor = data. ctor . map ( |( kind, index) | ( kind, self . local_def_id ( index) ) ) ;
873878
874- ty:: VariantDef :: new (
875- self . item_name ( index) ,
876- variant_did,
877- ctor,
878- data. discr ,
879- self . root
880- . tables
881- . children
882- . get ( self , index)
883- . expect ( "fields are not encoded for a variant" )
884- . decode ( self )
885- . map ( |index| ty:: FieldDef {
886- did : self . local_def_id ( index) ,
887- name : self . item_name ( index) ,
888- vis : self . get_visibility ( index) ,
889- } )
890- . collect ( ) ,
891- adt_kind,
892- parent_did,
893- false ,
894- data. is_non_exhaustive ,
879+ (
880+ data. idx ,
881+ ty:: VariantDef :: new (
882+ self . item_name ( index) ,
883+ variant_did,
884+ ctor,
885+ data. discr ,
886+ self . root
887+ . tables
888+ . children
889+ . get ( self , index)
890+ . expect ( "fields are not encoded for a variant" )
891+ . decode ( self )
892+ . map ( |index| ty:: FieldDef {
893+ did : self . local_def_id ( index) ,
894+ name : self . item_name ( index) ,
895+ vis : self . get_visibility ( index) ,
896+ } )
897+ . collect ( ) ,
898+ adt_kind,
899+ parent_did,
900+ false ,
901+ data. is_non_exhaustive ,
902+ ) ,
895903 )
896904 }
897905
@@ -907,7 +915,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
907915 } ;
908916 let repr = self . root . tables . repr_options . get ( self , item_id) . unwrap ( ) . decode ( self ) ;
909917
910- let variants = if let ty:: AdtKind :: Enum = adt_kind {
918+ let mut variants: Vec < _ > = if let ty:: AdtKind :: Enum = adt_kind {
911919 self . root
912920 . tables
913921 . children
@@ -918,15 +926,22 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
918926 let kind = self . def_kind ( index) ;
919927 match kind {
920928 DefKind :: Ctor ( ..) => None ,
921- _ => Some ( self . get_variant ( & kind, index, did) ) ,
929+ _ => Some ( self . get_variant ( kind, index, did) ) ,
922930 }
923931 } )
924932 . collect ( )
925933 } else {
926- std:: iter:: once ( self . get_variant ( & kind, item_id, did) ) . collect ( )
934+ std:: iter:: once ( self . get_variant ( kind, item_id, did) ) . collect ( )
927935 } ;
928936
929- tcx. mk_adt_def ( did, adt_kind, variants, repr)
937+ variants. sort_by_key ( |( idx, _) | * idx) ;
938+
939+ tcx. mk_adt_def (
940+ did,
941+ adt_kind,
942+ variants. into_iter ( ) . map ( |( _, variant) | variant) . collect ( ) ,
943+ repr,
944+ )
930945 }
931946
932947 fn get_visibility ( self , id : DefIndex ) -> Visibility < DefId > {
0 commit comments