rustdoc: Render methods/impls for bare traits
This renders a "Methods" and "Trait Implementations" section for each item implemented for a bare trait itself. Closes #19055
This commit is contained in:
parent
ba402312fe
commit
8f6855c8c8
2 changed files with 65 additions and 32 deletions
|
@ -920,9 +920,10 @@ impl DocFolder for Cache {
|
||||||
let path = match self.paths.get(&did) {
|
let path = match self.paths.get(&did) {
|
||||||
Some(&(_, ItemType::Trait)) =>
|
Some(&(_, ItemType::Trait)) =>
|
||||||
Some(&self.stack[..self.stack.len() - 1]),
|
Some(&self.stack[..self.stack.len() - 1]),
|
||||||
// The current stack not necessarily has correlation for
|
// The current stack not necessarily has correlation
|
||||||
// where the type was defined. On the other hand,
|
// for where the type was defined. On the other
|
||||||
// `paths` always has the right information if present.
|
// hand, `paths` always has the right
|
||||||
|
// information if present.
|
||||||
Some(&(ref fqp, ItemType::Struct)) |
|
Some(&(ref fqp, ItemType::Struct)) |
|
||||||
Some(&(ref fqp, ItemType::Enum)) =>
|
Some(&(ref fqp, ItemType::Enum)) =>
|
||||||
Some(&fqp[..fqp.len() - 1]),
|
Some(&fqp[..fqp.len() - 1]),
|
||||||
|
@ -1861,6 +1862,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||||
try!(write!(w, "</div>"));
|
try!(write!(w, "</div>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there are methods directly on this trait object, render them here.
|
||||||
|
try!(render_methods(w, it));
|
||||||
|
|
||||||
let cache = cache();
|
let cache = cache();
|
||||||
try!(write!(w, "
|
try!(write!(w, "
|
||||||
<h2 id='implementors'>Implementors</h2>
|
<h2 id='implementors'>Implementors</h2>
|
||||||
|
@ -2179,37 +2183,36 @@ enum MethodLink {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_methods(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
|
fn render_methods(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
|
||||||
match cache().impls.get(&it.def_id) {
|
let v = match cache().impls.get(&it.def_id) {
|
||||||
Some(v) => {
|
Some(v) => v.clone(),
|
||||||
let (non_trait, traits): (Vec<_>, _) = v.iter().cloned()
|
None => return Ok(()),
|
||||||
.partition(|i| i.impl_.trait_.is_none());
|
};
|
||||||
if non_trait.len() > 0 {
|
let (non_trait, traits): (Vec<_>, _) = v.into_iter()
|
||||||
try!(write!(w, "<h2 id='methods'>Methods</h2>"));
|
.partition(|i| i.impl_.trait_.is_none());
|
||||||
for i in &non_trait {
|
if non_trait.len() > 0 {
|
||||||
try!(render_impl(w, i, MethodLink::Anchor));
|
try!(write!(w, "<h2 id='methods'>Methods</h2>"));
|
||||||
}
|
for i in &non_trait {
|
||||||
}
|
try!(render_impl(w, i, MethodLink::Anchor));
|
||||||
if traits.len() > 0 {
|
}
|
||||||
try!(write!(w, "<h2 id='implementations'>Trait \
|
}
|
||||||
Implementations</h2>"));
|
if traits.len() > 0 {
|
||||||
let (derived, manual): (Vec<_>, _) = traits.into_iter()
|
try!(write!(w, "<h2 id='implementations'>Trait \
|
||||||
.partition(|i| i.impl_.derived);
|
Implementations</h2>"));
|
||||||
for i in &manual {
|
let (derived, manual): (Vec<_>, _) = traits.into_iter()
|
||||||
let did = i.trait_did().unwrap();
|
.partition(|i| i.impl_.derived);
|
||||||
try!(render_impl(w, i, MethodLink::GotoSource(did)));
|
for i in &manual {
|
||||||
}
|
let did = i.trait_did().unwrap();
|
||||||
if derived.len() > 0 {
|
try!(render_impl(w, i, MethodLink::GotoSource(did)));
|
||||||
try!(write!(w, "<h3 id='derived_implementations'>\
|
}
|
||||||
Derived Implementations \
|
if derived.len() > 0 {
|
||||||
</h3>"));
|
try!(write!(w, "<h3 id='derived_implementations'>\
|
||||||
for i in &derived {
|
Derived Implementations \
|
||||||
let did = i.trait_did().unwrap();
|
</h3>"));
|
||||||
try!(render_impl(w, i, MethodLink::GotoSource(did)));
|
for i in &derived {
|
||||||
}
|
let did = i.trait_did().unwrap();
|
||||||
}
|
try!(render_impl(w, i, MethodLink::GotoSource(did)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
30
src/test/rustdoc/issue-19055.rs
Normal file
30
src/test/rustdoc/issue-19055.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// @has issue_19055/trait.Any.html
|
||||||
|
pub trait Any {}
|
||||||
|
|
||||||
|
impl<'any> Any + 'any {
|
||||||
|
// @has - '//*[@id="method.is"]' 'fn is'
|
||||||
|
pub fn is<T: 'static>(&self) -> bool { loop {} }
|
||||||
|
|
||||||
|
// @has - '//*[@id="method.downcast_ref"]' 'fn downcast_ref'
|
||||||
|
pub fn downcast_ref<T: 'static>(&self) -> Option<&T> { loop {} }
|
||||||
|
|
||||||
|
// @has - '//*[@id="method.downcast_mut"]' 'fn downcast_mut'
|
||||||
|
pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T> { loop {} }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Foo {
|
||||||
|
fn foo(&self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @has - '//*[@id="method.foo"]' 'fn foo'
|
||||||
|
impl Foo for Any {}
|
Loading…
Add table
Add a link
Reference in a new issue