14
14
//! or contains "invocation-specific".
15
15
16
16
use std:: cell:: RefCell ;
17
+ use std:: cmp:: Ordering ;
17
18
use std:: ffi:: OsString ;
18
19
use std:: fs:: File ;
19
20
use std:: io:: { self , Write as _} ;
@@ -46,6 +47,7 @@ use crate::formats::Impl;
46
47
use crate :: formats:: item_type:: ItemType ;
47
48
use crate :: html:: layout;
48
49
use crate :: html:: render:: ordered_json:: { EscapedJson , OrderedJson } ;
50
+ use crate :: html:: render:: print_item:: compare_names;
49
51
use crate :: html:: render:: search_index:: { SerializedSearchIndex , build_index} ;
50
52
use crate :: html:: render:: sorted_template:: { self , FileFormat , SortedTemplate } ;
51
53
use crate :: html:: render:: { AssocItemLink , ImplRenderingParameters , StylePath } ;
@@ -703,7 +705,7 @@ impl TraitAliasPart {
703
705
fn blank ( ) -> SortedTemplate < <Self as CciPart >:: FileFormat > {
704
706
SortedTemplate :: from_before_after (
705
707
r"(function() {
706
- var implementors = Object.fromEntries([" ,
708
+ const implementors = Object.fromEntries([" ,
707
709
r"]);
708
710
if (window.register_implementors) {
709
711
window.register_implementors(implementors);
@@ -741,7 +743,7 @@ impl TraitAliasPart {
741
743
} ,
742
744
} ;
743
745
744
- let implementors = imps
746
+ let mut implementors = imps
745
747
. iter ( )
746
748
. filter_map ( |imp| {
747
749
// If the trait and implementation are in the same crate, then
@@ -756,10 +758,12 @@ impl TraitAliasPart {
756
758
{
757
759
None
758
760
} else {
761
+ let impl_ = imp. inner_impl ( ) ;
759
762
Some ( Implementor {
760
- text : imp . inner_impl ( ) . print ( false , cx) . to_string ( ) ,
763
+ text : impl_ . print ( false , cx) . to_string ( ) ,
761
764
synthetic : imp. inner_impl ( ) . kind . is_auto ( ) ,
762
765
types : collect_paths_for_type ( & imp. inner_impl ( ) . for_ , cache) ,
766
+ is_negative : impl_. is_negative_trait_impl ( ) ,
763
767
} )
764
768
}
765
769
} )
@@ -778,7 +782,9 @@ impl TraitAliasPart {
778
782
}
779
783
path. push ( format ! ( "{remote_item_type}.{}.js" , remote_path[ remote_path. len( ) - 1 ] ) ) ;
780
784
781
- let part = OrderedJson :: array_sorted (
785
+ implementors. sort_unstable ( ) ;
786
+
787
+ let part = OrderedJson :: array_unsorted (
782
788
implementors
783
789
. iter ( )
784
790
. map ( OrderedJson :: serialize)
@@ -791,10 +797,12 @@ impl TraitAliasPart {
791
797
}
792
798
}
793
799
800
+ #[ derive( PartialEq , Eq ) ]
794
801
struct Implementor {
795
802
text : String ,
796
803
synthetic : bool ,
797
804
types : Vec < String > ,
805
+ is_negative : bool ,
798
806
}
799
807
800
808
impl Serialize for Implementor {
@@ -804,6 +812,7 @@ impl Serialize for Implementor {
804
812
{
805
813
let mut seq = serializer. serialize_seq ( None ) ?;
806
814
seq. serialize_element ( & self . text ) ?;
815
+ seq. serialize_element ( if self . is_negative { & 1 } else { & 0 } ) ?;
807
816
if self . synthetic {
808
817
seq. serialize_element ( & 1 ) ?;
809
818
seq. serialize_element ( & self . types ) ?;
@@ -812,6 +821,22 @@ impl Serialize for Implementor {
812
821
}
813
822
}
814
823
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
+
815
840
/// Collect the list of aliased types and their aliases.
816
841
/// <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+type.impl&type=code>
817
842
///
0 commit comments