@@ -856,7 +856,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
856
856
ty:: EarlyBinder ( & * output)
857
857
}
858
858
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 ) {
860
865
let adt_kind = match kind {
861
866
DefKind :: Variant => ty:: AdtKind :: Enum ,
862
867
DefKind :: Struct => ty:: AdtKind :: Struct ,
@@ -870,22 +875,25 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
870
875
if adt_kind == ty:: AdtKind :: Enum { Some ( self . local_def_id ( index) ) } else { None } ;
871
876
let ctor = data. ctor . map ( |( kind, index) | ( kind, self . local_def_id ( index) ) ) ;
872
877
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
+ ) ,
889
897
)
890
898
}
891
899
@@ -901,7 +909,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
901
909
} ;
902
910
let repr = self . root . tables . repr_options . get ( self , item_id) . unwrap ( ) . decode ( self ) ;
903
911
904
- let variants = if let ty:: AdtKind :: Enum = adt_kind {
912
+ let mut variants: Vec < _ > = if let ty:: AdtKind :: Enum = adt_kind {
905
913
self . root
906
914
. tables
907
915
. module_children_non_reexports
@@ -912,15 +920,22 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
912
920
let kind = self . def_kind ( index) ;
913
921
match kind {
914
922
DefKind :: Ctor ( ..) => None ,
915
- _ => Some ( self . get_variant ( & kind, index, did) ) ,
923
+ _ => Some ( self . get_variant ( kind, index, did) ) ,
916
924
}
917
925
} )
918
926
. collect ( )
919
927
} 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 ( )
921
929
} ;
922
930
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
+ )
924
939
}
925
940
926
941
fn get_visibility ( self , id : DefIndex ) -> Visibility < DefId > {
0 commit comments