@@ -63,7 +63,9 @@ use rustc_span::symbol::{sym, Symbol};
63
63
use serde:: ser:: SerializeSeq ;
64
64
use serde:: { Serialize , Serializer } ;
65
65
66
- use crate :: clean:: { self , AttributesExt , Deprecation , GetDefId , RenderedLink , SelfTy , TypeKind } ;
66
+ use crate :: clean:: {
67
+ self , AttributesExt , Deprecation , GetDefId , ImplPolarity , RenderedLink , SelfTy , TypeKind ,
68
+ } ;
67
69
use crate :: config:: { RenderInfo , RenderOptions } ;
68
70
use crate :: docfs:: { DocFS , PathError } ;
69
71
use crate :: doctree;
@@ -2532,6 +2534,16 @@ fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl) -> Ordering {
2532
2534
compare_names ( & lhs, & rhs)
2533
2535
}
2534
2536
2537
+ fn compare_impl_polarity ( a : & Impl , b : & Impl ) -> Ordering {
2538
+ match ( a. inner_impl ( ) . polarity . as_ref ( ) , b. inner_impl ( ) . polarity . as_ref ( ) ) {
2539
+ ( Some ( ImplPolarity :: Positive ) , Some ( ImplPolarity :: Negative ) ) => Ordering :: Greater ,
2540
+ ( Some ( ImplPolarity :: Negative ) , Some ( ImplPolarity :: Positive ) ) => Ordering :: Less ,
2541
+ ( Some ( ImplPolarity :: Positive ) , Some ( ImplPolarity :: Positive ) )
2542
+ | ( Some ( ImplPolarity :: Negative ) , Some ( ImplPolarity :: Negative ) ) => Ordering :: Equal ,
2543
+ ( None , _) | ( _, None ) => Ordering :: Equal ,
2544
+ }
2545
+ }
2546
+
2535
2547
fn item_trait ( w : & mut Buffer , cx : & Context , it : & clean:: Item , t : & clean:: Trait , cache : & Cache ) {
2536
2548
let bounds = bounds ( & t. bounds , false ) ;
2537
2549
let types = t. items . iter ( ) . filter ( |m| m. is_associated_type ( ) ) . collect :: < Vec < _ > > ( ) ;
@@ -2718,6 +2730,10 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
2718
2730
}
2719
2731
}
2720
2732
2733
+ let mut implementors = implementors. clone ( ) ;
2734
+
2735
+ implementors. sort_by ( compare_impl_polarity) ;
2736
+
2721
2737
let ( local, foreign) = implementors. iter ( ) . partition :: < Vec < _ > , _ > ( |i| {
2722
2738
i. inner_impl ( ) . for_ . def_id ( ) . map_or ( true , |d| cache. paths . contains_key ( & d) )
2723
2739
} ) ;
0 commit comments