@@ -4234,13 +4234,30 @@ impl<'a> fmt::Display for Sidebar<'a> {
42344234 }
42354235}
42364236
4237- fn get_methods ( i : & clean:: Impl , for_deref : bool ) -> Vec < String > {
4237+ fn get_next_url ( used_links : & mut FxHashSet < String > , url : String ) -> String {
4238+ if used_links. insert ( url. clone ( ) ) {
4239+ return url;
4240+ }
4241+ let mut add = 1 ;
4242+ while used_links. insert ( format ! ( "{}-{}" , url, add) ) == false {
4243+ add += 1 ;
4244+ }
4245+ format ! ( "{}-{}" , url, add)
4246+ }
4247+
4248+ fn get_methods (
4249+ i : & clean:: Impl ,
4250+ for_deref : bool ,
4251+ used_links : & mut FxHashSet < String > ,
4252+ ) -> Vec < String > {
42384253 i. items . iter ( ) . filter_map ( |item| {
42394254 match item. name {
42404255 // Maybe check with clean::Visibility::Public as well?
42414256 Some ( ref name) if !name. is_empty ( ) && item. visibility . is_some ( ) && item. is_method ( ) => {
42424257 if !for_deref || should_render_item ( item, false ) {
4243- Some ( format ! ( "<a href=\" #method.{name}\" >{name}</a>" , name = name) )
4258+ Some ( format ! ( "<a href=\" #{}\" >{}</a>" ,
4259+ get_next_url( used_links, format!( "method.{}" , name) ) ,
4260+ name) )
42444261 } else {
42454262 None
42464263 }
@@ -4270,13 +4287,20 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
42704287 let mut out = String :: new ( ) ;
42714288 let c = cache ( ) ;
42724289 if let Some ( v) = c. impls . get ( & it. def_id ) {
4273- let ret = v. iter ( )
4274- . filter ( |i| i. inner_impl ( ) . trait_ . is_none ( ) )
4275- . flat_map ( |i| get_methods ( i. inner_impl ( ) , false ) )
4276- . collect :: < String > ( ) ;
4277- if !ret. is_empty ( ) {
4278- out. push_str ( & format ! ( "<a class=\" sidebar-title\" href=\" #methods\" >Methods\
4279- </a><div class=\" sidebar-links\" >{}</div>", ret) ) ;
4290+ let mut used_links = FxHashSet :: default ( ) ;
4291+
4292+ {
4293+ let used_links_bor = Rc :: new ( RefCell :: new ( & mut used_links) ) ;
4294+ let ret = v. iter ( )
4295+ . filter ( |i| i. inner_impl ( ) . trait_ . is_none ( ) )
4296+ . flat_map ( move |i| get_methods ( i. inner_impl ( ) ,
4297+ false ,
4298+ & mut used_links_bor. borrow_mut ( ) ) )
4299+ . collect :: < String > ( ) ;
4300+ if !ret. is_empty ( ) {
4301+ out. push_str ( & format ! ( "<a class=\" sidebar-title\" href=\" #methods\" >Methods\
4302+ </a><div class=\" sidebar-links\" >{}</div>", ret) ) ;
4303+ }
42804304 }
42814305
42824306 if v. iter ( ) . any ( |i| i. inner_impl ( ) . trait_ . is_some ( ) ) {
@@ -4301,35 +4325,38 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
43014325 out. push_str ( "</a>" ) ;
43024326 let ret = impls. iter ( )
43034327 . filter ( |i| i. inner_impl ( ) . trait_ . is_none ( ) )
4304- . flat_map ( |i| get_methods ( i. inner_impl ( ) , true ) )
4328+ . flat_map ( |i| get_methods ( i. inner_impl ( ) ,
4329+ true ,
4330+ & mut used_links) )
43054331 . collect :: < String > ( ) ;
43064332 out. push_str ( & format ! ( "<div class=\" sidebar-links\" >{}</div>" , ret) ) ;
43074333 }
43084334 }
43094335 }
43104336 let format_impls = |impls : Vec < & Impl > | {
43114337 let mut links = FxHashSet :: default ( ) ;
4338+
43124339 impls. iter ( )
4313- . filter_map ( |i| {
4314- let is_negative_impl = is_negative_impl ( i. inner_impl ( ) ) ;
4315- if let Some ( ref i) = i. inner_impl ( ) . trait_ {
4316- let i_display = format ! ( "{:#}" , i) ;
4317- let out = Escape ( & i_display) ;
4318- let encoded = small_url_encode ( & format ! ( "{:#}" , i) ) ;
4319- let generated = format ! ( "<a href=\" #impl-{}\" >{}{}</a>" ,
4320- encoded,
4321- if is_negative_impl { "!" } else { "" } ,
4322- out) ;
4323- if links. insert ( generated. clone ( ) ) {
4324- Some ( generated)
4325- } else {
4326- None
4327- }
4328- } else {
4329- None
4330- }
4331- } )
4332- . collect :: < String > ( )
4340+ . filter_map ( |i| {
4341+ let is_negative_impl = is_negative_impl ( i. inner_impl ( ) ) ;
4342+ if let Some ( ref i) = i. inner_impl ( ) . trait_ {
4343+ let i_display = format ! ( "{:#}" , i) ;
4344+ let out = Escape ( & i_display) ;
4345+ let encoded = small_url_encode ( & format ! ( "{:#}" , i) ) ;
4346+ let generated = format ! ( "<a href=\" #impl-{}\" >{}{}</a>" ,
4347+ encoded,
4348+ if is_negative_impl { "!" } else { "" } ,
4349+ out) ;
4350+ if links. insert ( generated. clone ( ) ) {
4351+ Some ( generated)
4352+ } else {
4353+ None
4354+ }
4355+ } else {
4356+ None
4357+ }
4358+ } )
4359+ . collect :: < String > ( )
43334360 } ;
43344361
43354362 let ( synthetic, concrete) : ( Vec < & Impl > , Vec < & Impl > ) = v
0 commit comments