);
@@ -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 {
@@ -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, "",
- *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, "",
+ *item.name.as_ref().unwrap(),
+ shortty(item)));
try!(render_assoc_item(w, item, link));
- try!(write!(w, "
\n"));
+ try!(write!(w, "
\n"));
+ }
}
clean::TypedefItem(ref tydef) => {
let name = item.name.as_ref().unwrap();
@@ -2389,22 +2389,36 @@ 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, ""));
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 }) {
@@ -2412,7 +2426,7 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
None => {}
}
- try!(doctraititem(w, trait_item, AssocItemLink::GotoSource(did)));
+ try!(doctraititem(w, trait_item, AssocItemLink::GotoSource(did), render_static));
}
Ok(())
}
@@ -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, "
"));
diff --git a/src/test/auxiliary/issue-19190-3.rs b/src/test/auxiliary/issue-19190-3.rs
index 435f0176162..7403bcf4afb 100644
--- a/src/test/auxiliary/issue-19190-3.rs
+++ b/src/test/auxiliary/issue-19190-3.rs
@@ -22,6 +22,7 @@ pub struct Baz;
impl Baz {
pub fn baz(&self) {}
+ pub fn static_baz() {}
}
impl Deref for Bar {
diff --git a/src/test/rustdoc/issue-19190-2.rs b/src/test/rustdoc/issue-19190-2.rs
index b84ec6d6166..8835e18f1c5 100644
--- a/src/test/rustdoc/issue-19190-2.rs
+++ b/src/test/rustdoc/issue-19190-2.rs
@@ -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'
diff --git a/src/test/rustdoc/issue-19190-3.rs b/src/test/rustdoc/issue-19190-3.rs
index eec5c025377..64c396b29f2 100644
--- a/src/test/rustdoc/issue-19190-3.rs
+++ b/src/test/rustdoc/issue-19190-3.rs
@@ -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 {
diff --git a/src/test/rustdoc/issue-19190.rs b/src/test/rustdoc/issue-19190.rs
index f011a3e64a6..6289fcc6fe5 100644
--- a/src/test/rustdoc/issue-19190.rs
+++ b/src/test/rustdoc/issue-19190.rs
@@ -15,6 +15,7 @@ pub struct Bar;
impl Foo {
pub fn foo(&self) {}
+ pub fn static_foo() {}
}
impl Deref for Bar {
@@ -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()'