1414//! or contains "invocation-specific".
1515
1616use std:: cell:: RefCell ;
17+ use std:: cmp:: Ordering ;
1718use std:: ffi:: OsString ;
1819use std:: fs:: File ;
1920use std:: io:: { self , Write as _} ;
@@ -46,6 +47,7 @@ use crate::formats::Impl;
4647use crate :: formats:: item_type:: ItemType ;
4748use crate :: html:: layout;
4849use crate :: html:: render:: ordered_json:: { EscapedJson , OrderedJson } ;
50+ use crate :: html:: render:: print_item:: compare_names;
4951use crate :: html:: render:: search_index:: { SerializedSearchIndex , build_index} ;
5052use crate :: html:: render:: sorted_template:: { self , FileFormat , SortedTemplate } ;
5153use crate :: html:: render:: { AssocItemLink , ImplRenderingParameters , StylePath } ;
@@ -703,7 +705,7 @@ impl TraitAliasPart {
703705 fn blank ( ) -> SortedTemplate < <Self as CciPart >:: FileFormat > {
704706 SortedTemplate :: from_before_after (
705707 r"(function() {
706- var implementors = Object.fromEntries([" ,
708+ const implementors = Object.fromEntries([" ,
707709 r"]);
708710 if (window.register_implementors) {
709711 window.register_implementors(implementors);
@@ -741,7 +743,7 @@ impl TraitAliasPart {
741743 } ,
742744 } ;
743745
744- let implementors = imps
746+ let mut implementors = imps
745747 . iter ( )
746748 . filter_map ( |imp| {
747749 // If the trait and implementation are in the same crate, then
@@ -756,10 +758,12 @@ impl TraitAliasPart {
756758 {
757759 None
758760 } else {
761+ let impl_ = imp. inner_impl ( ) ;
759762 Some ( Implementor {
760- text : imp . inner_impl ( ) . print ( false , cx) . to_string ( ) ,
763+ text : impl_ . print ( false , cx) . to_string ( ) ,
761764 synthetic : imp. inner_impl ( ) . kind . is_auto ( ) ,
762765 types : collect_paths_for_type ( & imp. inner_impl ( ) . for_ , cache) ,
766+ is_negative : impl_. is_negative_trait_impl ( ) ,
763767 } )
764768 }
765769 } )
@@ -778,7 +782,9 @@ impl TraitAliasPart {
778782 }
779783 path. push ( format ! ( "{remote_item_type}.{}.js" , remote_path[ remote_path. len( ) - 1 ] ) ) ;
780784
781- let part = OrderedJson :: array_sorted (
785+ implementors. sort_unstable ( ) ;
786+
787+ let part = OrderedJson :: array_unsorted (
782788 implementors
783789 . iter ( )
784790 . map ( OrderedJson :: serialize)
@@ -791,10 +797,12 @@ impl TraitAliasPart {
791797 }
792798}
793799
800+ #[ derive( PartialEq , Eq ) ]
794801struct Implementor {
795802 text : String ,
796803 synthetic : bool ,
797804 types : Vec < String > ,
805+ is_negative : bool ,
798806}
799807
800808impl Serialize for Implementor {
@@ -804,6 +812,7 @@ impl Serialize for Implementor {
804812 {
805813 let mut seq = serializer. serialize_seq ( None ) ?;
806814 seq. serialize_element ( & self . text ) ?;
815+ seq. serialize_element ( if self . is_negative { & 1 } else { & 0 } ) ?;
807816 if self . synthetic {
808817 seq. serialize_element ( & 1 ) ?;
809818 seq. serialize_element ( & self . types ) ?;
@@ -812,6 +821,22 @@ impl Serialize for Implementor {
812821 }
813822}
814823
824+ impl PartialOrd for Implementor {
825+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
826+ Some ( Ord :: cmp ( self , other) )
827+ }
828+ }
829+
830+ impl Ord for Implementor {
831+ fn cmp ( & self , other : & Self ) -> Ordering {
832+ match ( self . is_negative , other. is_negative ) {
833+ ( false , true ) => Ordering :: Greater ,
834+ ( true , false ) => Ordering :: Less ,
835+ _ => compare_names ( & self . text , & other. text ) ,
836+ }
837+ }
838+ }
839+
815840/// Collect the list of aliased types and their aliases.
816841/// <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+type.impl&type=code>
817842///
0 commit comments