1
Fork 0

Fix rustdoc formatting of impls

Some cases displayed negative impls as positive, and some were missing
where clauses.  This factors all the impl formatting into one
function so the different cases can't get out of sync again.
This commit is contained in:
William Throwe 2015-07-18 02:02:57 -04:00
parent e4e93196e1
commit 456770472b
2 changed files with 18 additions and 24 deletions

View file

@ -540,6 +540,19 @@ impl fmt::Display for clean::Type {
} }
} }
impl fmt::Display for clean::Impl {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "impl{} ", self.generics));
if let Some(ref ty) = self.trait_ {
try!(write!(f, "{}{} for ",
if self.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" },
*ty));
}
try!(write!(f, "{}{}", self.for_, WhereClause(&self.generics)));
Ok(())
}
}
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() {

View file

@ -118,11 +118,8 @@ pub enum ExternalLocation {
/// Metadata about an implementor of a trait. /// Metadata about an implementor of a trait.
pub struct Implementor { pub struct Implementor {
pub def_id: ast::DefId, pub def_id: ast::DefId,
pub generics: clean::Generics,
pub trait_: clean::Type,
pub for_: clean::Type,
pub stability: Option<clean::Stability>, pub stability: Option<clean::Stability>,
pub polarity: Option<clean::ImplPolarity>, pub impl_: clean::Impl,
} }
/// Metadata about implementations for a type. /// Metadata about implementations for a type.
@ -644,10 +641,7 @@ fn write_shared(cx: &Context,
// going on). If they're in different crates then the crate defining // going on). If they're in different crates then the crate defining
// the trait will be interested in our implementation. // the trait will be interested in our implementation.
if imp.def_id.krate == did.krate { continue } if imp.def_id.krate == did.krate { continue }
try!(write!(&mut f, r#""impl{} {}{} for {}","#, try!(write!(&mut f, r#""{}","#, imp.impl_));
imp.generics,
if imp.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" },
imp.trait_, imp.for_));
} }
try!(writeln!(&mut f, r"];")); try!(writeln!(&mut f, r"];"));
try!(writeln!(&mut f, "{}", r" try!(writeln!(&mut f, "{}", r"
@ -888,11 +882,8 @@ impl DocFolder for Cache {
Some(clean::ResolvedPath{ did, .. }) => { Some(clean::ResolvedPath{ did, .. }) => {
self.implementors.entry(did).or_insert(vec![]).push(Implementor { self.implementors.entry(did).or_insert(vec![]).push(Implementor {
def_id: item.def_id, def_id: item.def_id,
generics: i.generics.clone(),
trait_: i.trait_.as_ref().unwrap().clone(),
for_: i.for_.clone(),
stability: item.stability.clone(), stability: item.stability.clone(),
polarity: i.polarity.clone(), impl_: i.clone(),
}); });
} }
Some(..) | None => {} Some(..) | None => {}
@ -1910,8 +1901,7 @@ 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 {
try!(writeln!(w, "<li><code>impl{} {} for {}{}</code></li>", try!(writeln!(w, "<li><code>{}</code></li>", i.impl_));
i.generics, i.trait_, i.for_, WhereClause(&i.generics)));
} }
} }
None => {} None => {}
@ -2335,16 +2325,7 @@ fn render_deref_methods(w: &mut fmt::Formatter, impl_: &Impl) -> fmt::Result {
fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink, fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
render_header: bool) -> fmt::Result { render_header: bool) -> fmt::Result {
if render_header { if render_header {
try!(write!(w, "<h3 class='impl'><code>impl{} ", try!(write!(w, "<h3 class='impl'><code>{}</code></h3>", i.impl_));
i.impl_.generics));
if let Some(clean::ImplPolarity::Negative) = i.impl_.polarity {
try!(write!(w, "!"));
}
if let Some(ref ty) = i.impl_.trait_ {
try!(write!(w, "{} for ", *ty));
}
try!(write!(w, "{}{}</code></h3>", i.impl_.for_,
WhereClause(&i.impl_.generics)));
if let Some(ref dox) = i.dox { if let Some(ref dox) = i.dox {
try!(write!(w, "<div class='docblock'>{}</div>", Markdown(dox))); try!(write!(w, "<div class='docblock'>{}</div>", Markdown(dox)));
} }