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,8 +746,22 @@ 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_by ( |a, b| {
751+ // We sort negative impls first.
752+ match ( a. is_negative , b. is_negative ) {
753+ ( false , true ) => Ordering :: Greater ,
754+ ( true , false ) => Ordering :: Less ,
755+ _ => compare_names ( & a. text , & b. text ) ,
756+ }
757+ } ) ;
758+
759+ let part = OrderedJson :: array_unsorted (
760+ implementors
761+ . iter ( )
762+ . map ( OrderedJson :: serialize)
763+ . collect :: < Result < Vec < _ > , _ > > ( )
764+ . unwrap ( ) ,
747765 ) ;
748766 path_parts. push ( path, OrderedJson :: array_unsorted ( [ crate_name_json, & part] ) ) ;
749767 }
@@ -755,6 +773,7 @@ struct Implementor {
755773 text : String ,
756774 synthetic : bool ,
757775 types : Vec < String > ,
776+ is_negative : bool ,
758777}
759778
760779impl Serialize for Implementor {
@@ -764,6 +783,7 @@ impl Serialize for Implementor {
764783 {
765784 let mut seq = serializer. serialize_seq ( None ) ?;
766785 seq. serialize_element ( & self . text ) ?;
786+ seq. serialize_element ( if self . is_negative { & 1 } else { & 0 } ) ?;
767787 if self . synthetic {
768788 seq. serialize_element ( & 1 ) ?;
769789 seq. serialize_element ( & self . types ) ?;
0 commit comments