Skip to content

Commit 4567704

Browse files
committed
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.
1 parent e4e9319 commit 4567704

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

src/librustdoc/html/format.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,19 @@ impl fmt::Display for clean::Type {
540540
}
541541
}
542542

543+
impl fmt::Display for clean::Impl {
544+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
545+
try!(write!(f, "impl{} ", self.generics));
546+
if let Some(ref ty) = self.trait_ {
547+
try!(write!(f, "{}{} for ",
548+
if self.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" },
549+
*ty));
550+
}
551+
try!(write!(f, "{}{}", self.for_, WhereClause(&self.generics)));
552+
Ok(())
553+
}
554+
}
555+
543556
impl fmt::Display for clean::Arguments {
544557
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
545558
for (i, input) in self.values.iter().enumerate() {

src/librustdoc/html/render.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,8 @@ pub enum ExternalLocation {
118118
/// Metadata about an implementor of a trait.
119119
pub struct Implementor {
120120
pub def_id: ast::DefId,
121-
pub generics: clean::Generics,
122-
pub trait_: clean::Type,
123-
pub for_: clean::Type,
124121
pub stability: Option<clean::Stability>,
125-
pub polarity: Option<clean::ImplPolarity>,
122+
pub impl_: clean::Impl,
126123
}
127124

128125
/// Metadata about implementations for a type.
@@ -644,10 +641,7 @@ fn write_shared(cx: &Context,
644641
// going on). If they're in different crates then the crate defining
645642
// the trait will be interested in our implementation.
646643
if imp.def_id.krate == did.krate { continue }
647-
try!(write!(&mut f, r#""impl{} {}{} for {}","#,
648-
imp.generics,
649-
if imp.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" },
650-
imp.trait_, imp.for_));
644+
try!(write!(&mut f, r#""{}","#, imp.impl_));
651645
}
652646
try!(writeln!(&mut f, r"];"));
653647
try!(writeln!(&mut f, "{}", r"
@@ -888,11 +882,8 @@ impl DocFolder for Cache {
888882
Some(clean::ResolvedPath{ did, .. }) => {
889883
self.implementors.entry(did).or_insert(vec![]).push(Implementor {
890884
def_id: item.def_id,
891-
generics: i.generics.clone(),
892-
trait_: i.trait_.as_ref().unwrap().clone(),
893-
for_: i.for_.clone(),
894885
stability: item.stability.clone(),
895-
polarity: i.polarity.clone(),
886+
impl_: i.clone(),
896887
});
897888
}
898889
Some(..) | None => {}
@@ -1910,8 +1901,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
19101901
match cache.implementors.get(&it.def_id) {
19111902
Some(implementors) => {
19121903
for i in implementors {
1913-
try!(writeln!(w, "<li><code>impl{} {} for {}{}</code></li>",
1914-
i.generics, i.trait_, i.for_, WhereClause(&i.generics)));
1904+
try!(writeln!(w, "<li><code>{}</code></li>", i.impl_));
19151905
}
19161906
}
19171907
None => {}
@@ -2335,16 +2325,7 @@ fn render_deref_methods(w: &mut fmt::Formatter, impl_: &Impl) -> fmt::Result {
23352325
fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
23362326
render_header: bool) -> fmt::Result {
23372327
if render_header {
2338-
try!(write!(w, "<h3 class='impl'><code>impl{} ",
2339-
i.impl_.generics));
2340-
if let Some(clean::ImplPolarity::Negative) = i.impl_.polarity {
2341-
try!(write!(w, "!"));
2342-
}
2343-
if let Some(ref ty) = i.impl_.trait_ {
2344-
try!(write!(w, "{} for ", *ty));
2345-
}
2346-
try!(write!(w, "{}{}</code></h3>", i.impl_.for_,
2347-
WhereClause(&i.impl_.generics)));
2328+
try!(write!(w, "<h3 class='impl'><code>{}</code></h3>", i.impl_));
23482329
if let Some(ref dox) = i.dox {
23492330
try!(write!(w, "<div class='docblock'>{}</div>", Markdown(dox)));
23502331
}

0 commit comments

Comments
 (0)