@@ -2300,17 +2300,21 @@ fn document_non_exhaustive(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::R
2300
2300
}
2301
2301
2302
2302
fn name_key ( name : & str ) -> ( & str , u64 , usize ) {
2303
+ let end = name. bytes ( )
2304
+ . rposition ( |b| b. is_ascii_digit ( ) ) . map_or ( name. len ( ) , |i| i + 1 ) ;
2305
+
2303
2306
// find number at end
2304
- let split = name. bytes ( ) . rposition ( |b| b < b'0' || b'9' < b) . map_or ( 0 , |s| s + 1 ) ;
2307
+ let split = name[ 0 ..end] . bytes ( )
2308
+ . rposition ( |b| !b. is_ascii_digit ( ) ) . map_or ( 0 , |i| i + 1 ) ;
2305
2309
2306
2310
// count leading zeroes
2307
2311
let after_zeroes =
2308
- name[ split..] . bytes ( ) . position ( |b| b != b'0' ) . map_or ( name. len ( ) , |extra| split + extra) ;
2312
+ name[ split..end ] . bytes ( ) . position ( |b| b != b'0' ) . map_or ( name. len ( ) , |extra| split + extra) ;
2309
2313
2310
2314
// sort leading zeroes last
2311
2315
let num_zeroes = after_zeroes - split;
2312
2316
2313
- match name[ split..] . parse ( ) {
2317
+ match name[ split..end ] . parse ( ) {
2314
2318
Ok ( n) => ( & name[ ..split] , n, num_zeroes) ,
2315
2319
Err ( _) => ( name, 0 , num_zeroes) ,
2316
2320
}
@@ -2701,6 +2705,14 @@ fn bounds(t_bounds: &[clean::GenericBound]) -> String {
2701
2705
bounds
2702
2706
}
2703
2707
2708
+ fn compare_impl < ' a , ' b > ( lhs : & ' a & & Impl , rhs : & ' b & & Impl ) -> Ordering {
2709
+ let lhs = format ! ( "{}" , lhs. inner_impl( ) ) ;
2710
+ let rhs = format ! ( "{}" , rhs. inner_impl( ) ) ;
2711
+
2712
+ // lhs and rhs are formatted as HTML, which may be unnecessary
2713
+ name_key ( & lhs) . cmp ( & name_key ( & rhs) )
2714
+ }
2715
+
2704
2716
fn item_trait (
2705
2717
w : & mut fmt:: Formatter ,
2706
2718
cx : & Context ,
@@ -2904,9 +2916,12 @@ fn item_trait(
2904
2916
. map_or ( true , |d| cache. paths . contains_key ( & d) ) ) ;
2905
2917
2906
2918
2907
- let ( synthetic, concrete) : ( Vec < & & Impl > , Vec < & & Impl > ) = local. iter ( )
2919
+ let ( mut synthetic, mut concrete) : ( Vec < & & Impl > , Vec < & & Impl > ) = local. iter ( )
2908
2920
. partition ( |i| i. inner_impl ( ) . synthetic ) ;
2909
2921
2922
+ synthetic. sort_by ( compare_impl) ;
2923
+ concrete. sort_by ( compare_impl) ;
2924
+
2910
2925
if !foreign. is_empty ( ) {
2911
2926
write ! ( w, "
2912
2927
<h2 id='foreign-impls' class='small-section-header'>
@@ -4715,6 +4730,7 @@ fn test_name_sorting() {
4715
4730
"Fruit1" , "Fruit01" ,
4716
4731
"Fruit2" , "Fruit02" ,
4717
4732
"Fruit20" ,
4733
+ "Fruit30x" ,
4718
4734
"Fruit100" ,
4719
4735
"Pear" ] ;
4720
4736
let mut sorted = names. to_owned ( ) ;
0 commit comments