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 } ;
@@ -650,7 +652,7 @@ impl TraitAliasPart {
650652 fn blank ( ) -> SortedTemplate < <Self as CciPart >:: FileFormat > {
651653 SortedTemplate :: from_before_after (
652654 r"(function() {
653- var implementors = Object.fromEntries([" ,
655+ const implementors = Object.fromEntries([" ,
654656 r"]);
655657 if (window.register_implementors) {
656658 window.register_implementors(implementors);
@@ -703,10 +705,12 @@ impl TraitAliasPart {
703705 {
704706 None
705707 } else {
708+ let impl_ = imp. inner_impl ( ) ;
706709 Some ( Implementor {
707- text : imp . inner_impl ( ) . print ( false , cx) . to_string ( ) ,
710+ text : impl_ . print ( false , cx) . to_string ( ) ,
708711 synthetic : imp. inner_impl ( ) . kind . is_auto ( ) ,
709712 types : collect_paths_for_type ( & imp. inner_impl ( ) . for_ , cache) ,
713+ is_negative : impl_. is_negative_trait_impl ( ) ,
710714 } )
711715 }
712716 } )
@@ -725,19 +729,28 @@ impl TraitAliasPart {
725729 }
726730 path. push ( format ! ( "{remote_item_type}.{}.js" , remote_path[ remote_path. len( ) - 1 ] ) ) ;
727731
728- let part = OrderedJson :: array_sorted (
729- implementors. map ( |implementor| OrderedJson :: serialize ( implementor) . unwrap ( ) ) ,
732+ let mut implementors = implementors. collect :: < Vec < _ > > ( ) ;
733+ implementors. sort_unstable ( ) ;
734+
735+ let part = OrderedJson :: array_unsorted (
736+ implementors
737+ . iter ( )
738+ . map ( OrderedJson :: serialize)
739+ . collect :: < Result < Vec < _ > , _ > > ( )
740+ . unwrap ( ) ,
730741 ) ;
731742 path_parts. push ( path, OrderedJson :: array_unsorted ( [ crate_name_json, & part] ) ) ;
732743 }
733744 Ok ( path_parts)
734745 }
735746}
736747
748+ #[ derive( Eq ) ]
737749struct Implementor {
738750 text : String ,
739751 synthetic : bool ,
740752 types : Vec < String > ,
753+ is_negative : bool ,
741754}
742755
743756impl Serialize for Implementor {
@@ -747,6 +760,7 @@ impl Serialize for Implementor {
747760 {
748761 let mut seq = serializer. serialize_seq ( None ) ?;
749762 seq. serialize_element ( & self . text ) ?;
763+ seq. serialize_element ( if self . is_negative { & 1 } else { & 0 } ) ?;
750764 if self . synthetic {
751765 seq. serialize_element ( & 1 ) ?;
752766 seq. serialize_element ( & self . types ) ?;
@@ -755,6 +769,29 @@ impl Serialize for Implementor {
755769 }
756770}
757771
772+ impl PartialEq for Implementor {
773+ fn eq ( & self , other : & Self ) -> bool {
774+ self . cmp ( other) == Ordering :: Equal
775+ }
776+ }
777+
778+ impl PartialOrd for Implementor {
779+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
780+ Some ( Ord :: cmp ( self , other) )
781+ }
782+ }
783+
784+ impl Ord for Implementor {
785+ fn cmp ( & self , other : & Self ) -> Ordering {
786+ // We sort negative impls first.
787+ match ( self . is_negative , other. is_negative ) {
788+ ( false , true ) => Ordering :: Greater ,
789+ ( true , false ) => Ordering :: Less ,
790+ _ => compare_names ( & self . text , & other. text ) ,
791+ }
792+ }
793+ }
794+
758795/// Collect the list of aliased types and their aliases.
759796/// <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+type.impl&type=code>
760797///
0 commit comments