Skip to content

Rustdoc: ignore deref-inherited static methods #24657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 37 additions & 22 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,20 @@ use std::sync::Arc;

use externalfiles::ExternalHtml;

use serialize::json;
use serialize::json::ToJson;
use syntax::abi;
use syntax::ast;
use syntax::ast_util;
use syntax::attr;
use serialize::json::{self, ToJson};
use syntax::{abi, ast, ast_util, attr};
use rustc::util::nodemap::NodeSet;

use clean;
use clean::{self, SelfTy};
use doctree;
use fold::DocFolder;
use html::escape::Escape;
use html::format::{ConstnessSpace};
use html::format::{TyParamBounds, WhereClause, href, AbiSpace};
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
use html::highlight;
use html::item_type::ItemType;
use html::layout;
use html::markdown::Markdown;
use html::markdown;
use html::markdown::{self, Markdown};
use html::{highlight, layout};

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

// Render_header is false when we are rendering a `Deref` impl and true
// otherwise. If render_header is false, we will avoid rendering static
// methods, since they are not accessible for the type implementing `Deref`
fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
render_header: bool) -> fmt::Result {
if render_header {
Expand All @@ -2348,14 +2345,17 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
}

fn doctraititem(w: &mut fmt::Formatter, item: &clean::Item,
link: AssocItemLink) -> fmt::Result {
link: AssocItemLink, render_static: bool) -> fmt::Result {
match item.inner {
clean::MethodItem(..) | clean::TyMethodItem(..) => {
try!(write!(w, "<h4 id='method.{}' class='{}'><code>",
*item.name.as_ref().unwrap(),
shortty(item)));
// Only render when the method is not static or we allow static methods
if !is_static_method(item) || render_static {
try!(write!(w, "<h4 id='method.{}' class='{}'><code>",
*item.name.as_ref().unwrap(),
shortty(item)));
try!(render_assoc_item(w, item, link));
try!(write!(w, "</code></h4>\n"));
try!(write!(w, "</code></h4>\n"));
}
}
clean::TypedefItem(ref tydef) => {
let name = item.name.as_ref().unwrap();
Expand Down Expand Up @@ -2389,30 +2389,44 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
}
_ => panic!("can't make docs for trait item with name {:?}", item.name)
}
if let AssocItemLink::Anchor = link {
document(w, item)

return if let AssocItemLink::Anchor = link {
if is_static_method(item) && !render_static {
Ok(())
} else {
document(w, item)
}
} else {
Ok(())
};

fn is_static_method(item: &clean::Item) -> bool {
match item.inner {
clean::MethodItem(ref method) => method.self_ == SelfTy::SelfStatic,
clean::TyMethodItem(ref method) => method.self_ == SelfTy::SelfStatic,
_ => false
}
}
}

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

fn render_default_items(w: &mut fmt::Formatter,
did: ast::DefId,
t: &clean::Trait,
i: &clean::Impl) -> fmt::Result {
i: &clean::Impl,
render_static: bool) -> fmt::Result {
for trait_item in &t.items {
let n = trait_item.name.clone();
match i.items.iter().find(|m| { m.name == n }) {
Some(..) => continue,
None => {}
}

try!(doctraititem(w, trait_item, AssocItemLink::GotoSource(did)));
try!(doctraititem(w, trait_item, AssocItemLink::GotoSource(did), render_static));
}
Ok(())
}
Expand All @@ -2423,7 +2437,8 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
// for them work.
if let Some(clean::ResolvedPath { did, .. }) = i.impl_.trait_ {
if let Some(t) = cache().traits.get(&did) {
try!(render_default_items(w, did, t, &i.impl_));
try!(render_default_items(w, did, t, &i.impl_, render_header));

}
}
try!(write!(w, "</div>"));
Expand Down
1 change: 1 addition & 0 deletions src/test/auxiliary/issue-19190-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct Baz;

impl Baz {
pub fn baz(&self) {}
pub fn static_baz() {}
}

impl Deref for Bar {
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/issue-19190-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ impl Deref for Bar {

// @has issue_19190_2/struct.Bar.html
// @has - '//*[@id="method.count_ones"]' 'fn count_ones(self) -> u32'

// @!has - '//*[@id="method.min_value"]' 'fn min_value() -> i32'
3 changes: 3 additions & 0 deletions src/test/rustdoc/issue-19190-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ use issue_19190_3::Baz;

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

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

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

impl Deref for MyBar {
Expand Down
2 changes: 2 additions & 0 deletions src/test/rustdoc/issue-19190.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Bar;

impl Foo {
pub fn foo(&self) {}
pub fn static_foo() {}
}

impl Deref for Bar {
Expand All @@ -24,3 +25,4 @@ impl Deref for Bar {

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