@@ -51,25 +51,19 @@ 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:: { TyParamBounds , WhereClause , href, AbiSpace } ;
67
63
use html:: format:: { VisSpace , Method , UnsafetySpace , MutableSpace } ;
68
- use html:: highlight;
69
64
use html:: item_type:: ItemType ;
70
- use html:: layout;
71
- use html:: markdown:: Markdown ;
72
- use html:: markdown;
65
+ use html:: markdown:: { self , Markdown } ;
66
+ use html:: { highlight, layout} ;
73
67
74
68
/// A pair of name and its optional document.
75
69
pub type NameDoc = ( String , Option < String > ) ;
@@ -2281,6 +2275,9 @@ fn render_deref_methods(w: &mut fmt::Formatter, impl_: &Impl) -> fmt::Result {
2281
2275
}
2282
2276
}
2283
2277
2278
+ // Render_header is false when we are rendering a `Deref` impl and true
2279
+ // otherwise. If render_header is false, we will avoid rendering static
2280
+ // methods, since they are not accessible for the type implementing `Deref`
2284
2281
fn render_impl ( w : & mut fmt:: Formatter , i : & Impl , link : MethodLink ,
2285
2282
render_header : bool ) -> fmt:: Result {
2286
2283
if render_header {
@@ -2300,14 +2297,17 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: MethodLink,
2300
2297
}
2301
2298
2302
2299
fn doctraititem ( w : & mut fmt:: Formatter , item : & clean:: Item ,
2303
- link : MethodLink ) -> fmt:: Result {
2300
+ link : MethodLink , render_static : bool ) -> fmt:: Result {
2304
2301
match item. inner {
2305
2302
clean:: MethodItem ( ..) | clean:: TyMethodItem ( ..) => {
2306
- try!( write ! ( w, "<h4 id='method.{}' class='{}'><code>" ,
2307
- * item. name. as_ref( ) . unwrap( ) ,
2308
- shortty( item) ) ) ;
2309
- try!( render_method ( w, item, link) ) ;
2310
- try!( write ! ( w, "</code></h4>\n " ) ) ;
2303
+ // Only render when the method is not static or we allow static methods
2304
+ if !is_static_method ( item) || render_static {
2305
+ try!( write ! ( w, "<h4 id='method.{}' class='{}'><code>" ,
2306
+ * item. name. as_ref( ) . unwrap( ) ,
2307
+ shortty( item) ) ) ;
2308
+ try!( render_method ( w, item, link) ) ;
2309
+ try!( write ! ( w, "</code></h4>\n " ) ) ;
2310
+ }
2311
2311
}
2312
2312
clean:: TypedefItem ( ref tydef) => {
2313
2313
let name = item. name . as_ref ( ) . unwrap ( ) ;
@@ -2327,30 +2327,44 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: MethodLink,
2327
2327
}
2328
2328
_ => panic ! ( "can't make docs for trait item with name {:?}" , item. name)
2329
2329
}
2330
- if let MethodLink :: Anchor = link {
2331
- document ( w, item)
2330
+
2331
+ return if let MethodLink :: Anchor = link {
2332
+ if is_static_method ( item) && !render_static {
2333
+ Ok ( ( ) )
2334
+ } else {
2335
+ document ( w, item)
2336
+ }
2332
2337
} else {
2333
2338
Ok ( ( ) )
2339
+ } ;
2340
+
2341
+ fn is_static_method ( item : & clean:: Item ) -> bool {
2342
+ match item. inner {
2343
+ clean:: MethodItem ( ref method) => method. self_ == SelfTy :: SelfStatic ,
2344
+ clean:: TyMethodItem ( ref method) => method. self_ == SelfTy :: SelfStatic ,
2345
+ _ => false
2346
+ }
2334
2347
}
2335
2348
}
2336
2349
2337
2350
try!( write ! ( w, "<div class='impl-items'>" ) ) ;
2338
2351
for trait_item in i. impl_ . items . iter ( ) {
2339
- try!( doctraititem ( w, trait_item, link) ) ;
2352
+ try!( doctraititem ( w, trait_item, link, render_header ) ) ;
2340
2353
}
2341
2354
2342
2355
fn render_default_methods ( w : & mut fmt:: Formatter ,
2343
2356
did : ast:: DefId ,
2344
2357
t : & clean:: Trait ,
2345
- i : & clean:: Impl ) -> fmt:: Result {
2358
+ i : & clean:: Impl ,
2359
+ render_static : bool ) -> fmt:: Result {
2346
2360
for trait_item in & t. items {
2347
2361
let n = trait_item. name . clone ( ) ;
2348
2362
match i. items . iter ( ) . find ( |m| { m. name == n } ) {
2349
2363
Some ( ..) => continue ,
2350
2364
None => { }
2351
2365
}
2352
2366
2353
- try!( doctraititem ( w, trait_item, MethodLink :: GotoSource ( did) ) ) ;
2367
+ try!( doctraititem ( w, trait_item, MethodLink :: GotoSource ( did) , render_static ) ) ;
2354
2368
}
2355
2369
Ok ( ( ) )
2356
2370
}
@@ -2361,7 +2375,7 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: MethodLink,
2361
2375
// for them work.
2362
2376
if let Some ( clean:: ResolvedPath { did, .. } ) = i. impl_ . trait_ {
2363
2377
if let Some ( t) = cache ( ) . traits . get ( & did) {
2364
- try!( render_default_methods ( w, did, t, & i. impl_ ) ) ;
2378
+ try!( render_default_methods ( w, did, t, & i. impl_ , render_header ) ) ;
2365
2379
}
2366
2380
}
2367
2381
try!( write ! ( w, "</div>" ) ) ;
0 commit comments