@@ -2300,17 +2300,21 @@ fn document_non_exhaustive(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::R
23002300}
23012301
23022302fn 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+
23032306 // 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 ) ;
23052309
23062310 // count leading zeroes
23072311 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) ;
23092313
23102314 // sort leading zeroes last
23112315 let num_zeroes = after_zeroes - split;
23122316
2313- match name[ split..] . parse ( ) {
2317+ match name[ split..end ] . parse ( ) {
23142318 Ok ( n) => ( & name[ ..split] , n, num_zeroes) ,
23152319 Err ( _) => ( name, 0 , num_zeroes) ,
23162320 }
@@ -2701,6 +2705,14 @@ fn bounds(t_bounds: &[clean::GenericBound]) -> String {
27012705 bounds
27022706}
27032707
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+
27042716fn item_trait (
27052717 w : & mut fmt:: Formatter ,
27062718 cx : & Context ,
@@ -2904,9 +2916,12 @@ fn item_trait(
29042916 . map_or ( true , |d| cache. paths . contains_key ( & d) ) ) ;
29052917
29062918
2907- let ( synthetic, concrete) : ( Vec < & & Impl > , Vec < & & Impl > ) = local. iter ( )
2919+ let ( mut synthetic, mut concrete) : ( Vec < & & Impl > , Vec < & & Impl > ) = local. iter ( )
29082920 . partition ( |i| i. inner_impl ( ) . synthetic ) ;
29092921
2922+ synthetic. sort_by ( compare_impl) ;
2923+ concrete. sort_by ( compare_impl) ;
2924+
29102925 if !foreign. is_empty ( ) {
29112926 write ! ( w, "
29122927 <h2 id='foreign-impls' class='small-section-header'>
@@ -4715,6 +4730,7 @@ fn test_name_sorting() {
47154730 "Fruit1" , "Fruit01" ,
47164731 "Fruit2" , "Fruit02" ,
47174732 "Fruit20" ,
4733+ "Fruit30x" ,
47184734 "Fruit100" ,
47194735 "Pear" ] ;
47204736 let mut sorted = names. to_owned ( ) ;
0 commit comments