@@ -51,26 +51,20 @@ use std::sync::Arc;
51
51
52
52
use externalfiles:: ExternalHtml ;
53
53
54
- use serialize:: json;
55
- use serialize:: json:: ToJson ;
56
- use syntax:: abi;
57
- use syntax:: ast;
58
- use syntax:: ast_util;
59
- use syntax:: attr;
54
+ use serialize:: json:: { self , ToJson } ;
55
+ use syntax:: { abi, ast, ast_util, attr} ;
60
56
use rustc:: util:: nodemap:: NodeSet ;
61
57
62
- use clean;
58
+ use clean:: { self , SelfTy } ;
63
59
use doctree;
64
60
use fold:: DocFolder ;
65
61
use html:: escape:: Escape ;
66
62
use html:: format:: { ConstnessSpace } ;
67
63
use html:: format:: { TyParamBounds , WhereClause , href, AbiSpace } ;
68
64
use html:: format:: { VisSpace , Method , UnsafetySpace , MutableSpace } ;
69
- use html:: highlight;
70
65
use html:: item_type:: ItemType ;
71
- use html:: layout;
72
- use html:: markdown:: Markdown ;
73
- use html:: markdown;
66
+ use html:: markdown:: { self , Markdown } ;
67
+ use html:: { highlight, layout} ;
74
68
75
69
/// A pair of name and its optional document.
76
70
pub type NameDoc = ( String , Option < String > ) ;
@@ -2329,6 +2323,9 @@ fn render_deref_methods(w: &mut fmt::Formatter, impl_: &Impl) -> fmt::Result {
2329
2323
}
2330
2324
}
2331
2325
2326
+ // Render_header is false when we are rendering a `Deref` impl and true
2327
+ // otherwise. If render_header is false, we will avoid rendering static
2328
+ // methods, since they are not accessible for the type implementing `Deref`
2332
2329
fn render_impl ( w : & mut fmt:: Formatter , i : & Impl , link : AssocItemLink ,
2333
2330
render_header : bool ) -> fmt:: Result {
2334
2331
if render_header {
@@ -2348,14 +2345,17 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
2348
2345
}
2349
2346
2350
2347
fn doctraititem ( w : & mut fmt:: Formatter , item : & clean:: Item ,
2351
- link : AssocItemLink ) -> fmt:: Result {
2348
+ link : AssocItemLink , render_static : bool ) -> fmt:: Result {
2352
2349
match item. inner {
2353
2350
clean:: MethodItem ( ..) | clean:: TyMethodItem ( ..) => {
2354
- try!( write ! ( w, "<h4 id='method.{}' class='{}'><code>" ,
2355
- * item. name. as_ref( ) . unwrap( ) ,
2356
- shortty( item) ) ) ;
2351
+ // Only render when the method is not static or we allow static methods
2352
+ if !is_static_method ( item) || render_static {
2353
+ try!( write ! ( w, "<h4 id='method.{}' class='{}'><code>" ,
2354
+ * item. name. as_ref( ) . unwrap( ) ,
2355
+ shortty( item) ) ) ;
2357
2356
try!( render_assoc_item ( w, item, link) ) ;
2358
- try!( write ! ( w, "</code></h4>\n " ) ) ;
2357
+ try!( write ! ( w, "</code></h4>\n " ) ) ;
2358
+ }
2359
2359
}
2360
2360
clean:: TypedefItem ( ref tydef) => {
2361
2361
let name = item. name . as_ref ( ) . unwrap ( ) ;
@@ -2389,30 +2389,44 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
2389
2389
}
2390
2390
_ => panic ! ( "can't make docs for trait item with name {:?}" , item. name)
2391
2391
}
2392
- if let AssocItemLink :: Anchor = link {
2393
- document ( w, item)
2392
+
2393
+ return if let AssocItemLink :: Anchor = link {
2394
+ if is_static_method ( item) && !render_static {
2395
+ Ok ( ( ) )
2396
+ } else {
2397
+ document ( w, item)
2398
+ }
2394
2399
} else {
2395
2400
Ok ( ( ) )
2401
+ } ;
2402
+
2403
+ fn is_static_method ( item : & clean:: Item ) -> bool {
2404
+ match item. inner {
2405
+ clean:: MethodItem ( ref method) => method. self_ == SelfTy :: SelfStatic ,
2406
+ clean:: TyMethodItem ( ref method) => method. self_ == SelfTy :: SelfStatic ,
2407
+ _ => false
2408
+ }
2396
2409
}
2397
2410
}
2398
2411
2399
2412
try!( write ! ( w, "<div class='impl-items'>" ) ) ;
2400
2413
for trait_item in i. impl_ . items . iter ( ) {
2401
- try!( doctraititem ( w, trait_item, link) ) ;
2414
+ try!( doctraititem ( w, trait_item, link, render_header ) ) ;
2402
2415
}
2403
2416
2404
2417
fn render_default_items ( w : & mut fmt:: Formatter ,
2405
2418
did : ast:: DefId ,
2406
2419
t : & clean:: Trait ,
2407
- i : & clean:: Impl ) -> fmt:: Result {
2420
+ i : & clean:: Impl ,
2421
+ render_static : bool ) -> fmt:: Result {
2408
2422
for trait_item in & t. items {
2409
2423
let n = trait_item. name . clone ( ) ;
2410
2424
match i. items . iter ( ) . find ( |m| { m. name == n } ) {
2411
2425
Some ( ..) => continue ,
2412
2426
None => { }
2413
2427
}
2414
2428
2415
- try!( doctraititem ( w, trait_item, AssocItemLink :: GotoSource ( did) ) ) ;
2429
+ try!( doctraititem ( w, trait_item, AssocItemLink :: GotoSource ( did) , render_static ) ) ;
2416
2430
}
2417
2431
Ok ( ( ) )
2418
2432
}
@@ -2423,7 +2437,8 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
2423
2437
// for them work.
2424
2438
if let Some ( clean:: ResolvedPath { did, .. } ) = i. impl_ . trait_ {
2425
2439
if let Some ( t) = cache ( ) . traits . get ( & did) {
2426
- try!( render_default_items ( w, did, t, & i. impl_ ) ) ;
2440
+ try!( render_default_items ( w, did, t, & i. impl_ , render_header) ) ;
2441
+
2427
2442
}
2428
2443
}
2429
2444
try!( write ! ( w, "</div>" ) ) ;
0 commit comments