@@ -37,7 +37,7 @@ pub use self::ExternalLocation::*;
37
37
use std:: ascii:: AsciiExt ;
38
38
use std:: cell:: RefCell ;
39
39
use std:: cmp:: Ordering ;
40
- use std:: collections:: BTreeMap ;
40
+ use std:: collections:: { BTreeMap , HashSet } ;
41
41
use std:: default:: Default ;
42
42
use std:: error;
43
43
use std:: fmt:: { self , Display , Formatter , Write as FmtWrite } ;
@@ -3206,12 +3206,37 @@ fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl,
3206
3206
}
3207
3207
}
3208
3208
3209
+ fn should_render_item ( item : & clean:: Item , deref_mut_ : bool ) -> bool {
3210
+ let self_type_opt = match item. inner {
3211
+ clean:: MethodItem ( ref method) => method. decl . self_type ( ) ,
3212
+ clean:: TyMethodItem ( ref method) => method. decl . self_type ( ) ,
3213
+ _ => None
3214
+ } ;
3215
+
3216
+ if let Some ( self_ty) = self_type_opt {
3217
+ let ( by_mut_ref, by_box) = match self_ty {
3218
+ SelfTy :: SelfBorrowed ( _, mutability) |
3219
+ SelfTy :: SelfExplicit ( clean:: BorrowedRef { mutability, .. } ) => {
3220
+ ( mutability == Mutability :: Mutable , false )
3221
+ } ,
3222
+ SelfTy :: SelfExplicit ( clean:: ResolvedPath { did, .. } ) => {
3223
+ ( false , Some ( did) == cache ( ) . owned_box_did )
3224
+ } ,
3225
+ _ => ( false , false ) ,
3226
+ } ;
3227
+
3228
+ ( deref_mut_ || !by_mut_ref) && !by_box
3229
+ } else {
3230
+ false
3231
+ }
3232
+ }
3233
+
3209
3234
fn render_impl ( w : & mut fmt:: Formatter , cx : & Context , i : & Impl , link : AssocItemLink ,
3210
3235
render_mode : RenderMode , outer_version : Option < & str > ,
3211
3236
show_def_docs : bool ) -> fmt:: Result {
3212
3237
if render_mode == RenderMode :: Normal {
3213
3238
let id = derive_id ( match i. inner_impl ( ) . trait_ {
3214
- Some ( ref t) => format ! ( "impl-{}" , Escape ( & format!( "{:#}" , t) ) ) ,
3239
+ Some ( ref t) => format ! ( "impl-{}" , small_url_encode ( & format!( "{:#}" , t) ) ) ,
3215
3240
None => "impl" . to_string ( ) ,
3216
3241
} ) ;
3217
3242
write ! ( w, "<h3 id='{}' class='impl'><span class='in-band'><code>{}</code>" ,
@@ -3243,30 +3268,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
3243
3268
3244
3269
let render_method_item: bool = match render_mode {
3245
3270
RenderMode :: Normal => true ,
3246
- RenderMode :: ForDeref { mut_ : deref_mut_ } => {
3247
- let self_type_opt = match item. inner {
3248
- clean:: MethodItem ( ref method) => method. decl . self_type ( ) ,
3249
- clean:: TyMethodItem ( ref method) => method. decl . self_type ( ) ,
3250
- _ => None
3251
- } ;
3252
-
3253
- if let Some ( self_ty) = self_type_opt {
3254
- let ( by_mut_ref, by_box) = match self_ty {
3255
- SelfTy :: SelfBorrowed ( _, mutability) |
3256
- SelfTy :: SelfExplicit ( clean:: BorrowedRef { mutability, .. } ) => {
3257
- ( mutability == Mutability :: Mutable , false )
3258
- } ,
3259
- SelfTy :: SelfExplicit ( clean:: ResolvedPath { did, .. } ) => {
3260
- ( false , Some ( did) == cache ( ) . owned_box_did )
3261
- } ,
3262
- _ => ( false , false ) ,
3263
- } ;
3264
-
3265
- ( deref_mut_ || !by_mut_ref) && !by_box
3266
- } else {
3267
- false
3268
- }
3269
- } ,
3271
+ RenderMode :: ForDeref { mut_ : deref_mut_ } => should_render_item ( & item, deref_mut_) ,
3270
3272
} ;
3271
3273
3272
3274
match item. inner {
@@ -3513,12 +3515,16 @@ impl<'a> fmt::Display for Sidebar<'a> {
3513
3515
}
3514
3516
}
3515
3517
3516
- fn get_methods ( i : & clean:: Impl ) -> Vec < String > {
3518
+ fn get_methods ( i : & clean:: Impl , for_deref : bool ) -> Vec < String > {
3517
3519
i. items . iter ( ) . filter_map ( |item| {
3518
3520
match item. name {
3519
3521
// Maybe check with clean::Visibility::Public as well?
3520
3522
Some ( ref name) if !name. is_empty ( ) && item. visibility . is_some ( ) && item. is_method ( ) => {
3521
- Some ( format ! ( "<a href=\" #method.{name}\" >{name}</a>" , name = name) )
3523
+ if !for_deref || should_render_item ( item, false ) {
3524
+ Some ( format ! ( "<a href=\" #method.{name}\" >{name}</a>" , name = name) )
3525
+ } else {
3526
+ None
3527
+ }
3522
3528
}
3523
3529
_ => None ,
3524
3530
}
@@ -3546,7 +3552,7 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
3546
3552
if let Some ( v) = c. impls . get ( & it. def_id ) {
3547
3553
let ret = v. iter ( )
3548
3554
. filter ( |i| i. inner_impl ( ) . trait_ . is_none ( ) )
3549
- . flat_map ( |i| get_methods ( i. inner_impl ( ) ) )
3555
+ . flat_map ( |i| get_methods ( i. inner_impl ( ) , false ) )
3550
3556
. collect :: < String > ( ) ;
3551
3557
if !ret. is_empty ( ) {
3552
3558
out. push_str ( & format ! ( "<a class=\" sidebar-title\" href=\" #methods\" >Methods\
@@ -3574,17 +3580,23 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
3574
3580
out. push_str ( "</a>" ) ;
3575
3581
let ret = impls. iter ( )
3576
3582
. filter ( |i| i. inner_impl ( ) . trait_ . is_none ( ) )
3577
- . flat_map ( |i| get_methods ( i. inner_impl ( ) ) )
3583
+ . flat_map ( |i| get_methods ( i. inner_impl ( ) , true ) )
3578
3584
. collect :: < String > ( ) ;
3579
3585
out. push_str ( & format ! ( "<div class=\" sidebar-links\" >{}</div>" , ret) ) ;
3580
3586
}
3581
3587
}
3582
3588
}
3589
+ let mut links = HashSet :: new ( ) ;
3583
3590
let ret = v. iter ( )
3584
3591
. filter_map ( |i| if let Some ( ref i) = i. inner_impl ( ) . trait_ {
3585
3592
let out = format ! ( "{:#}" , i) . replace ( "<" , "<" ) . replace ( ">" , ">" ) ;
3586
3593
let encoded = small_url_encode ( & format ! ( "{:#}" , i) ) ;
3587
- Some ( format ! ( "<a href=\" #impl-{:#}\" >{}</a>" , encoded, out) )
3594
+ let generated = format ! ( "<a href=\" #impl-{}\" >{}</a>" , encoded, out) ;
3595
+ if !links. contains ( & generated) && links. insert ( generated. clone ( ) ) {
3596
+ Some ( generated)
3597
+ } else {
3598
+ None
3599
+ }
3588
3600
} else {
3589
3601
None
3590
3602
} )
0 commit comments