Avoid linking to itself in implementors section of trait page
This commit is contained in:
parent
a11129701c
commit
b308a8c036
3 changed files with 38 additions and 10 deletions
|
@ -1505,6 +1505,13 @@ impl Type {
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn trait_name(&self) -> Option<String> {
|
||||||
|
match *self {
|
||||||
|
ResolvedPath { ref path, .. } => Some(path.last_name()),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetDefId for Type {
|
impl GetDefId for Type {
|
||||||
|
@ -1994,6 +2001,10 @@ impl Path {
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn last_name(&self) -> String {
|
||||||
|
self.segments.last().unwrap().name.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Path> for hir::Path {
|
impl Clean<Path> for hir::Path {
|
||||||
|
|
|
@ -561,19 +561,33 @@ impl fmt::Display for clean::Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fmt_impl(i: &clean::Impl, f: &mut fmt::Formatter, link_trait: bool) -> fmt::Result {
|
||||||
|
write!(f, "impl{} ", i.generics)?;
|
||||||
|
if let Some(ref ty) = i.trait_ {
|
||||||
|
write!(f, "{}",
|
||||||
|
if i.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" })?;
|
||||||
|
if link_trait {
|
||||||
|
write!(f, "{}", *ty)?;
|
||||||
|
} else {
|
||||||
|
write!(f, "{}", ty.trait_name().unwrap())?;
|
||||||
|
}
|
||||||
|
write!(f, " for ")?;
|
||||||
|
}
|
||||||
|
write!(f, "{}{}", i.for_, WhereClause(&i.generics))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for clean::Impl {
|
impl fmt::Display for clean::Impl {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "impl{} ", self.generics)?;
|
fmt_impl(self, f, true)
|
||||||
if let Some(ref ty) = self.trait_ {
|
|
||||||
write!(f, "{}{} for ",
|
|
||||||
if self.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" },
|
|
||||||
*ty)?;
|
|
||||||
}
|
|
||||||
write!(f, "{}{}", self.for_, WhereClause(&self.generics))?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The difference from above is that trait is not hyperlinked.
|
||||||
|
pub fn fmt_impl_for_trait_page(i: &clean::Impl, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt_impl(i, f, false)
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for clean::Arguments {
|
impl fmt::Display for clean::Arguments {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
for (i, input) in self.values.iter().enumerate() {
|
for (i, input) in self.values.iter().enumerate() {
|
||||||
|
@ -667,7 +681,7 @@ impl fmt::Display for clean::Import {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
clean::SimpleImport(ref name, ref src) => {
|
clean::SimpleImport(ref name, ref src) => {
|
||||||
if *name == src.path.segments.last().unwrap().name {
|
if *name == src.path.last_name() {
|
||||||
write!(f, "use {};", *src)
|
write!(f, "use {};", *src)
|
||||||
} else {
|
} else {
|
||||||
write!(f, "use {} as {};", *src, *name)
|
write!(f, "use {} as {};", *src, *name)
|
||||||
|
|
|
@ -69,6 +69,7 @@ use html::escape::Escape;
|
||||||
use html::format::{ConstnessSpace};
|
use html::format::{ConstnessSpace};
|
||||||
use html::format::{TyParamBounds, WhereClause, href, AbiSpace};
|
use html::format::{TyParamBounds, WhereClause, href, AbiSpace};
|
||||||
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
|
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
|
||||||
|
use html::format::fmt_impl_for_trait_page;
|
||||||
use html::item_type::ItemType;
|
use html::item_type::ItemType;
|
||||||
use html::markdown::{self, Markdown};
|
use html::markdown::{self, Markdown};
|
||||||
use html::{highlight, layout};
|
use html::{highlight, layout};
|
||||||
|
@ -2006,7 +2007,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||||
match cache.implementors.get(&it.def_id) {
|
match cache.implementors.get(&it.def_id) {
|
||||||
Some(implementors) => {
|
Some(implementors) => {
|
||||||
for i in implementors {
|
for i in implementors {
|
||||||
writeln!(w, "<li><code>{}</code></li>", i.impl_)?;
|
write!(w, "<li><code>")?;
|
||||||
|
fmt_impl_for_trait_page(&i.impl_, w)?;
|
||||||
|
writeln!(w, "</code></li>")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue