@@ -12,7 +12,6 @@ use rustc_data_structures::unord::UnordMap;
1212use  rustc_hashes:: Hash128 ; 
1313use  rustc_hir:: ItemId ; 
1414use  rustc_hir:: def_id:: { CrateNum ,  DefId ,  DefIdSet ,  LOCAL_CRATE } ; 
15- use  rustc_index:: Idx ; 
1615use  rustc_macros:: { HashStable ,  TyDecodable ,  TyEncodable } ; 
1716use  rustc_query_system:: ich:: StableHashingContext ; 
1817use  rustc_session:: config:: OptLevel ; 
@@ -526,39 +525,18 @@ impl<'tcx> CodegenUnit<'tcx> {
526525        tcx :  TyCtxt < ' tcx > , 
527526    )  -> Vec < ( MonoItem < ' tcx > ,  MonoItemData ) >  { 
528527        // The codegen tests rely on items being process in the same order as 
529-         // they appear in the file, so for local items, we sort by node_id  first 
528+         // they appear in the file, so for local items, we sort by span and def_path  first 
530529        #[ derive( PartialEq ,  Eq ,  PartialOrd ,  Ord ) ]  
531-         struct  ItemSortKey < ' tcx > ( Option < usize > ,  SymbolName < ' tcx > ) ; 
530+         struct  ItemSortKey < ' tcx > ( Option < Span > ,   Option < String > ,  SymbolName < ' tcx > ) ; 
532531
533532        fn  item_sort_key < ' tcx > ( tcx :  TyCtxt < ' tcx > ,  item :  MonoItem < ' tcx > )  -> ItemSortKey < ' tcx >  { 
534533            ItemSortKey ( 
535-                 match  item { 
536-                     MonoItem :: Fn ( ref  instance)  => { 
537-                         match  instance. def  { 
538-                             // We only want to take HirIds of user-defined 
539-                             // instances into account. The others don't matter for 
540-                             // the codegen tests and can even make item order 
541-                             // unstable. 
542-                             InstanceKind :: Item ( def)  => def. as_local ( ) . map ( Idx :: index) , 
543-                             InstanceKind :: VTableShim ( ..) 
544-                             | InstanceKind :: ReifyShim ( ..) 
545-                             | InstanceKind :: Intrinsic ( ..) 
546-                             | InstanceKind :: FnPtrShim ( ..) 
547-                             | InstanceKind :: Virtual ( ..) 
548-                             | InstanceKind :: ClosureOnceShim  {  .. } 
549-                             | InstanceKind :: ConstructCoroutineInClosureShim  {  .. } 
550-                             | InstanceKind :: DropGlue ( ..) 
551-                             | InstanceKind :: CloneShim ( ..) 
552-                             | InstanceKind :: ThreadLocalShim ( ..) 
553-                             | InstanceKind :: FnPtrAddrShim ( ..) 
554-                             | InstanceKind :: AsyncDropGlue ( ..) 
555-                             | InstanceKind :: FutureDropPollShim ( ..) 
556-                             | InstanceKind :: AsyncDropGlueCtorShim ( ..)  => None , 
557-                         } 
558-                     } 
559-                     MonoItem :: Static ( def_id)  => def_id. as_local ( ) . map ( Idx :: index) , 
560-                     MonoItem :: GlobalAsm ( item_id)  => Some ( item_id. owner_id . def_id . index ( ) ) , 
561-                 } , 
534+                 // For codegen tests purposes, we don't care about non-local items' order, 
535+                 // so we just sort non-local items by symbol names. 
536+                 item. local_span ( tcx) , 
537+                 item. def_id ( ) 
538+                     . as_local ( ) 
539+                     . map ( |_| tcx. def_path ( item. def_id ( ) ) . to_string_no_crate_verbose ( ) ) , 
562540                item. symbol_name ( tcx) , 
563541            ) 
564542        } 
0 commit comments