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