Skip to content

Commit 1742a01

Browse files
committed
Auto merge of #24657 - aochagavia:rustdoc, r=alexcrichton
Fixes #24575 Fixes #25673 r? @alexcrichton
2 parents 6a003ab + 8703883 commit 1742a01

File tree

5 files changed

+44
-23
lines changed

5 files changed

+44
-23
lines changed

src/librustdoc/html/render.rs

+37-22
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,20 @@ use std::sync::Arc;
5151

5252
use externalfiles::ExternalHtml;
5353

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};
6056
use rustc::util::nodemap::NodeSet;
6157

62-
use clean;
58+
use clean::{self, SelfTy};
6359
use doctree;
6460
use fold::DocFolder;
6561
use html::escape::Escape;
6662
use html::format::{ConstnessSpace};
6763
use html::format::{TyParamBounds, WhereClause, href, AbiSpace};
6864
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
69-
use html::highlight;
7065
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};
7468

7569
/// A pair of name and its optional document.
7670
pub type NameDoc = (String, Option<String>);
@@ -2329,6 +2323,9 @@ fn render_deref_methods(w: &mut fmt::Formatter, impl_: &Impl) -> fmt::Result {
23292323
}
23302324
}
23312325

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`
23322329
fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
23332330
render_header: bool) -> fmt::Result {
23342331
if render_header {
@@ -2348,14 +2345,17 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
23482345
}
23492346

23502347
fn doctraititem(w: &mut fmt::Formatter, item: &clean::Item,
2351-
link: AssocItemLink) -> fmt::Result {
2348+
link: AssocItemLink, render_static: bool) -> fmt::Result {
23522349
match item.inner {
23532350
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)));
23572356
try!(render_assoc_item(w, item, link));
2358-
try!(write!(w, "</code></h4>\n"));
2357+
try!(write!(w, "</code></h4>\n"));
2358+
}
23592359
}
23602360
clean::TypedefItem(ref tydef) => {
23612361
let name = item.name.as_ref().unwrap();
@@ -2389,30 +2389,44 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
23892389
}
23902390
_ => panic!("can't make docs for trait item with name {:?}", item.name)
23912391
}
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+
}
23942399
} else {
23952400
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+
}
23962409
}
23972410
}
23982411

23992412
try!(write!(w, "<div class='impl-items'>"));
24002413
for trait_item in i.impl_.items.iter() {
2401-
try!(doctraititem(w, trait_item, link));
2414+
try!(doctraititem(w, trait_item, link, render_header));
24022415
}
24032416

24042417
fn render_default_items(w: &mut fmt::Formatter,
24052418
did: ast::DefId,
24062419
t: &clean::Trait,
2407-
i: &clean::Impl) -> fmt::Result {
2420+
i: &clean::Impl,
2421+
render_static: bool) -> fmt::Result {
24082422
for trait_item in &t.items {
24092423
let n = trait_item.name.clone();
24102424
match i.items.iter().find(|m| { m.name == n }) {
24112425
Some(..) => continue,
24122426
None => {}
24132427
}
24142428

2415-
try!(doctraititem(w, trait_item, AssocItemLink::GotoSource(did)));
2429+
try!(doctraititem(w, trait_item, AssocItemLink::GotoSource(did), render_static));
24162430
}
24172431
Ok(())
24182432
}
@@ -2423,7 +2437,8 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
24232437
// for them work.
24242438
if let Some(clean::ResolvedPath { did, .. }) = i.impl_.trait_ {
24252439
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+
24272442
}
24282443
}
24292444
try!(write!(w, "</div>"));

src/test/auxiliary/issue-19190-3.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct Baz;
2222

2323
impl Baz {
2424
pub fn baz(&self) {}
25+
pub fn static_baz() {}
2526
}
2627

2728
impl Deref for Bar {

src/test/rustdoc/issue-19190-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ impl Deref for Bar {
1919

2020
// @has issue_19190_2/struct.Bar.html
2121
// @has - '//*[@id="method.count_ones"]' 'fn count_ones(self) -> u32'
22-
22+
// @!has - '//*[@id="method.min_value"]' 'fn min_value() -> i32'

src/test/rustdoc/issue-19190-3.rs

+3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ use issue_19190_3::Baz;
1818

1919
// @has issue_19190_3/struct.Foo.html
2020
// @has - '//*[@id="method.count_ones"]' 'fn count_ones(self) -> u32'
21+
// @!has - '//*[@id="method.min_value"]' 'fn min_value() -> i32'
2122
pub use issue_19190_3::Foo;
2223

2324
// @has issue_19190_3/struct.Bar.html
2425
// @has - '//*[@id="method.baz"]' 'fn baz(&self)'
26+
// @!has - '//*[@id="method.static_baz"]' 'fn static_baz()'
2527
pub use issue_19190_3::Bar;
2628

2729
// @has issue_19190_3/struct.MyBar.html
2830
// @has - '//*[@id="method.baz"]' 'fn baz(&self)'
31+
// @!has - '//*[@id="method.static_baz"]' 'fn static_baz()'
2932
pub struct MyBar;
3033

3134
impl Deref for MyBar {

src/test/rustdoc/issue-19190.rs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub struct Bar;
1515

1616
impl Foo {
1717
pub fn foo(&self) {}
18+
pub fn static_foo() {}
1819
}
1920

2021
impl Deref for Bar {
@@ -24,3 +25,4 @@ impl Deref for Bar {
2425

2526
// @has issue_19190/struct.Bar.html
2627
// @has - '//*[@id="method.foo"]' 'fn foo(&self)'
28+
// @!has - '//*[@id="method.static_foo"]' 'fn static_foo()'

0 commit comments

Comments
 (0)