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 } ;
@@ -695,7 +697,7 @@ impl TraitAliasPart {
695697 fn blank ( ) -> SortedTemplate < <Self as CciPart >:: FileFormat > {
696698 SortedTemplate :: from_before_after (
697699 r"(function() {
698- var implementors = Object.fromEntries([" ,
700+ const implementors = Object.fromEntries([" ,
699701 r"]);
700702 if (window.register_implementors) {
701703 window.register_implementors(implementors);
@@ -748,10 +750,12 @@ impl TraitAliasPart {
748750 {
749751 None
750752 } else {
753+ let impl_ = imp. inner_impl ( ) ;
751754 Some ( Implementor {
752- text : imp . inner_impl ( ) . print ( false , cx) . to_string ( ) ,
755+ text : impl_ . print ( false , cx) . to_string ( ) ,
753756 synthetic : imp. inner_impl ( ) . kind . is_auto ( ) ,
754757 types : collect_paths_for_type ( & imp. inner_impl ( ) . for_ , cache) ,
758+ is_negative : impl_. is_negative_trait_impl ( ) ,
755759 } )
756760 }
757761 } )
@@ -770,19 +774,28 @@ impl TraitAliasPart {
770774 }
771775 path. push ( format ! ( "{remote_item_type}.{}.js" , remote_path[ remote_path. len( ) - 1 ] ) ) ;
772776
773- let part = OrderedJson :: array_sorted (
774- implementors. map ( |implementor| OrderedJson :: serialize ( implementor) . unwrap ( ) ) ,
777+ let mut implementors = implementors. collect :: < Vec < _ > > ( ) ;
778+ implementors. sort_unstable ( ) ;
779+
780+ let part = OrderedJson :: array_unsorted (
781+ implementors
782+ . iter ( )
783+ . map ( OrderedJson :: serialize)
784+ . collect :: < Result < Vec < _ > , _ > > ( )
785+ . unwrap ( ) ,
775786 ) ;
776787 path_parts. push ( path, OrderedJson :: array_unsorted ( [ crate_name_json, & part] ) ) ;
777788 }
778789 Ok ( path_parts)
779790 }
780791}
781792
793+ #[ derive( Eq ) ]
782794struct Implementor {
783795 text : String ,
784796 synthetic : bool ,
785797 types : Vec < String > ,
798+ is_negative : bool ,
786799}
787800
788801impl Serialize for Implementor {
@@ -792,6 +805,7 @@ impl Serialize for Implementor {
792805 {
793806 let mut seq = serializer. serialize_seq ( None ) ?;
794807 seq. serialize_element ( & self . text ) ?;
808+ seq. serialize_element ( if self . is_negative { & 1 } else { & 0 } ) ?;
795809 if self . synthetic {
796810 seq. serialize_element ( & 1 ) ?;
797811 seq. serialize_element ( & self . types ) ?;
@@ -800,6 +814,29 @@ impl Serialize for Implementor {
800814 }
801815}
802816
817+ impl PartialEq for Implementor {
818+ fn eq ( & self , other : & Self ) -> bool {
819+ self . cmp ( other) == Ordering :: Equal
820+ }
821+ }
822+
823+ impl PartialOrd for Implementor {
824+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
825+ Some ( Ord :: cmp ( self , other) )
826+ }
827+ }
828+
829+ impl Ord for Implementor {
830+ fn cmp ( & self , other : & Self ) -> Ordering {
831+ // We sort negative impls first.
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+
803840/// Collect the list of aliased types and their aliases.
804841/// <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+type.impl&type=code>
805842///
0 commit comments