1414//! or contains "invocation-specific".
1515
1616use std:: cell:: RefCell ;
17+ use std:: cmp:: Ordering ;
1718use std:: ffi:: { OsStr , OsString } ;
1819use std:: fs:: File ;
1920use std:: io:: { self , Write as _} ;
@@ -47,6 +48,7 @@ use crate::formats::item_type::ItemType;
4748use crate :: html:: format:: { print_impl, print_path} ;
4849use crate :: html:: layout;
4950use crate :: html:: render:: ordered_json:: { EscapedJson , OrderedJson } ;
51+ use crate :: html:: render:: print_item:: compare_names;
5052use crate :: html:: render:: search_index:: { SerializedSearchIndex , build_index} ;
5153use crate :: html:: render:: sorted_template:: { self , FileFormat , SortedTemplate } ;
5254use crate :: html:: render:: { AssocItemLink , ImplRenderingParameters , StylePath } ;
@@ -667,7 +669,7 @@ impl TraitAliasPart {
667669 fn blank ( ) -> SortedTemplate < <Self as CciPart >:: FileFormat > {
668670 SortedTemplate :: from_before_after (
669671 r"(function() {
670- var implementors = Object.fromEntries([" ,
672+ const implementors = Object.fromEntries([" ,
671673 r"]);
672674 if (window.register_implementors) {
673675 window.register_implementors(implementors);
@@ -720,10 +722,12 @@ impl TraitAliasPart {
720722 {
721723 None
722724 } else {
725+ let impl_ = imp. inner_impl ( ) ;
723726 Some ( Implementor {
724- text : print_impl ( imp . inner_impl ( ) , false , cx) . to_string ( ) ,
727+ text : print_impl ( impl_ , false , cx) . to_string ( ) ,
725728 synthetic : imp. inner_impl ( ) . kind . is_auto ( ) ,
726729 types : collect_paths_for_type ( & imp. inner_impl ( ) . for_ , cache) ,
730+ is_negative : impl_. is_negative_trait_impl ( ) ,
727731 } )
728732 }
729733 } )
@@ -742,19 +746,28 @@ impl TraitAliasPart {
742746 }
743747 path. push ( format ! ( "{remote_item_type}.{}.js" , remote_path[ remote_path. len( ) - 1 ] ) ) ;
744748
745- let part = OrderedJson :: array_sorted (
746- implementors. map ( |implementor| OrderedJson :: serialize ( implementor) . unwrap ( ) ) ,
749+ let mut implementors = implementors. collect :: < Vec < _ > > ( ) ;
750+ implementors. sort_unstable ( ) ;
751+
752+ let part = OrderedJson :: array_unsorted (
753+ implementors
754+ . iter ( )
755+ . map ( OrderedJson :: serialize)
756+ . collect :: < Result < Vec < _ > , _ > > ( )
757+ . unwrap ( ) ,
747758 ) ;
748759 path_parts. push ( path, OrderedJson :: array_unsorted ( [ crate_name_json, & part] ) ) ;
749760 }
750761 Ok ( path_parts)
751762 }
752763}
753764
765+ #[ derive( Eq ) ]
754766struct Implementor {
755767 text : String ,
756768 synthetic : bool ,
757769 types : Vec < String > ,
770+ is_negative : bool ,
758771}
759772
760773impl Serialize for Implementor {
@@ -764,6 +777,7 @@ impl Serialize for Implementor {
764777 {
765778 let mut seq = serializer. serialize_seq ( None ) ?;
766779 seq. serialize_element ( & self . text ) ?;
780+ seq. serialize_element ( if self . is_negative { & 1 } else { & 0 } ) ?;
767781 if self . synthetic {
768782 seq. serialize_element ( & 1 ) ?;
769783 seq. serialize_element ( & self . types ) ?;
@@ -772,6 +786,29 @@ impl Serialize for Implementor {
772786 }
773787}
774788
789+ impl PartialEq for Implementor {
790+ fn eq ( & self , other : & Self ) -> bool {
791+ self . cmp ( other) == Ordering :: Equal
792+ }
793+ }
794+
795+ impl PartialOrd for Implementor {
796+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
797+ Some ( Ord :: cmp ( self , other) )
798+ }
799+ }
800+
801+ impl Ord for Implementor {
802+ fn cmp ( & self , other : & Self ) -> Ordering {
803+ // We sort negative impls first.
804+ match ( self . is_negative , other. is_negative ) {
805+ ( false , true ) => Ordering :: Greater ,
806+ ( true , false ) => Ordering :: Less ,
807+ _ => compare_names ( & self . text , & other. text ) ,
808+ }
809+ }
810+ }
811+
775812/// Collect the list of aliased types and their aliases.
776813/// <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+type.impl&type=code>
777814///
0 commit comments