parent
2bc0bf2586
commit
87038831f1
@ -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>);
|
||||
@ -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, "<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();
|
||||
@ -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, "<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 }) {
|
||||
@ -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, "</div>"));
|
||||
|
@ -22,6 +22,7 @@ pub struct Baz;
|
||||
|
||||
impl Baz {
|
||||
pub fn baz(&self) {}
|
||||
pub fn static_baz() {}
|
||||
}
|
||||
|
||||
impl Deref for Bar {
|
||||
|
@ -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'
|
||||
|
@ -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 {
|
||||
|
@ -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()'
|
||||
|
Loading…
x
Reference in New Issue
Block a user