@@ -1811,23 +1811,53 @@ fn get_next_url(used_links: &mut FxHashSet<String>, url: String) -> String {
18111811 format ! ( "{}-{}" , url, add)
18121812}
18131813
1814+ struct SidebarLink {
1815+ name : Symbol ,
1816+ url : String ,
1817+ }
1818+
1819+ impl fmt:: Display for SidebarLink {
1820+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1821+ write ! ( f, "<a href=\" #{}\" >{}</a>" , self . url, self . name)
1822+ }
1823+ }
1824+
1825+ impl PartialEq for SidebarLink {
1826+ fn eq ( & self , other : & Self ) -> bool {
1827+ self . url == other. url
1828+ }
1829+ }
1830+
1831+ impl Eq for SidebarLink { }
1832+
1833+ impl PartialOrd for SidebarLink {
1834+ fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
1835+ Some ( self . cmp ( other) )
1836+ }
1837+ }
1838+
1839+ impl Ord for SidebarLink {
1840+ fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
1841+ self . url . cmp ( & other. url )
1842+ }
1843+ }
1844+
18141845fn get_methods (
18151846 i : & clean:: Impl ,
18161847 for_deref : bool ,
18171848 used_links : & mut FxHashSet < String > ,
18181849 deref_mut : bool ,
18191850 tcx : TyCtxt < ' _ > ,
1820- ) -> Vec < String > {
1851+ ) -> Vec < SidebarLink > {
18211852 i. items
18221853 . iter ( )
18231854 . filter_map ( |item| match item. name {
1824- Some ( ref name) if !name. is_empty ( ) && item. is_method ( ) => {
1855+ Some ( name) if !name. is_empty ( ) && item. is_method ( ) => {
18251856 if !for_deref || should_render_item ( item, deref_mut, tcx) {
1826- Some ( format ! (
1827- "<a href=\" #{}\" >{}</a>" ,
1828- get_next_url( used_links, format!( "method.{}" , name) ) ,
1829- name
1830- ) )
1857+ Some ( SidebarLink {
1858+ name,
1859+ url : get_next_url ( used_links, format ! ( "method.{}" , name) ) ,
1860+ } )
18311861 } else {
18321862 None
18331863 }
@@ -1837,6 +1867,22 @@ fn get_methods(
18371867 . collect :: < Vec < _ > > ( )
18381868}
18391869
1870+ fn get_associated_constants (
1871+ i : & clean:: Impl ,
1872+ used_links : & mut FxHashSet < String > ,
1873+ ) -> Vec < SidebarLink > {
1874+ i. items
1875+ . iter ( )
1876+ . filter_map ( |item| match item. name {
1877+ Some ( name) if !name. is_empty ( ) && item. is_associated_const ( ) => Some ( SidebarLink {
1878+ name,
1879+ url : get_next_url ( used_links, format ! ( "associatedconstant.{}" , name) ) ,
1880+ } ) ,
1881+ _ => None ,
1882+ } )
1883+ . collect :: < Vec < _ > > ( )
1884+ }
1885+
18401886// The point is to url encode any potential character from a type with genericity.
18411887fn small_url_encode ( s : String ) -> String {
18421888 let mut st = String :: new ( ) ;
@@ -1881,23 +1927,40 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
18811927
18821928 {
18831929 let used_links_bor = & mut used_links;
1884- let mut ret = v
1930+ let mut assoc_consts = v
1931+ . iter ( )
1932+ . flat_map ( |i| get_associated_constants ( i. inner_impl ( ) , used_links_bor) )
1933+ . collect :: < Vec < _ > > ( ) ;
1934+ if !assoc_consts. is_empty ( ) {
1935+ // We want links' order to be reproducible so we don't use unstable sort.
1936+ assoc_consts. sort ( ) ;
1937+
1938+ out. push_str (
1939+ "<h3 class=\" sidebar-title\" >\
1940+ <a href=\" #implementations\" >Associated Constants</a>\
1941+ </h3>\
1942+ <div class=\" sidebar-links\" >",
1943+ ) ;
1944+ for line in assoc_consts {
1945+ write ! ( out, "{}" , line) ;
1946+ }
1947+ out. push_str ( "</div>" ) ;
1948+ }
1949+ let mut methods = v
18851950 . iter ( )
18861951 . filter ( |i| i. inner_impl ( ) . trait_ . is_none ( ) )
1887- . flat_map ( move |i| {
1888- get_methods ( i. inner_impl ( ) , false , used_links_bor, false , cx. tcx ( ) )
1889- } )
1952+ . flat_map ( |i| get_methods ( i. inner_impl ( ) , false , used_links_bor, false , cx. tcx ( ) ) )
18901953 . collect :: < Vec < _ > > ( ) ;
1891- if !ret . is_empty ( ) {
1954+ if !methods . is_empty ( ) {
18921955 // We want links' order to be reproducible so we don't use unstable sort.
1893- ret . sort ( ) ;
1956+ methods . sort ( ) ;
18941957
18951958 out. push_str (
18961959 "<h3 class=\" sidebar-title\" ><a href=\" #implementations\" >Methods</a></h3>\
18971960 <div class=\" sidebar-links\" >",
18981961 ) ;
1899- for line in ret {
1900- out . push_str ( & line) ;
1962+ for line in methods {
1963+ write ! ( out , "{}" , line) ;
19011964 }
19021965 out. push_str ( "</div>" ) ;
19031966 }
@@ -2032,7 +2095,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
20322095 ret. sort ( ) ;
20332096 out. push_str ( "<div class=\" sidebar-links\" >" ) ;
20342097 for link in ret {
2035- out . push_str ( & link) ;
2098+ write ! ( out , "{}" , link) ;
20362099 }
20372100 out. push_str ( "</div>" ) ;
20382101 }
0 commit comments