Skip to content

Commit 238765e

Browse files
committed
Auto merge of #27103 - wthrowe:doc_format, r=alexcrichton
This fixes a couple of bugs visible on https://doc.rust-lang.org/nightly/std/marker/trait.Sync.html . For example: * `impl<T> Sync for *const T` should read `impl<T> !Sync for *const T` * `impl<T> !Sync for Weak<T>` should read `impl<T> !Sync for Weak<T> where T: ?Sized` This does change a struct in librustdoc and it seems that almost everything there is marked public, so if librustdoc has stability guarantees that could be a problem. If it is, I'll find a way to rework the change to avoid modifying public structures.
2 parents 118a5c4 + a3e78f4 commit 238765e

File tree

5 files changed

+86
-24
lines changed

5 files changed

+86
-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
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(optin_builtin_traits)]
12+
13+
pub trait AnOibit {}
14+
15+
impl AnOibit for .. {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:rustdoc-impl-parts-crosscrate.rs
12+
// ignore-cross-compile
13+
14+
#![feature(optin_builtin_traits)]
15+
16+
extern crate rustdoc_impl_parts_crosscrate;
17+
18+
pub struct Bar<T> { t: T }
19+
20+
// The output file is html embeded in javascript, so the html tags
21+
// aren't stripped by the processing script and we can't check for the
22+
// full impl string. Instead, just make sure something from each part
23+
// is mentioned.
24+
25+
// @has implementors/rustdoc_impl_parts_crosscrate/trait.AnOibit.js Bar
26+
// @has - Send
27+
// @has - !AnOibit
28+
// @has - Copy
29+
impl<T: Send> !rustdoc_impl_parts_crosscrate::AnOibit for Bar<T>
30+
where T: Copy {}

src/test/rustdoc/impl-parts.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(optin_builtin_traits)]
12+
13+
pub trait AnOibit {}
14+
15+
impl AnOibit for .. {}
16+
17+
pub struct Foo<T> { field: T }
18+
19+
// @has impl_parts/struct.Foo.html '//*[@class="impl"]//code' \
20+
// "impl<T: Clone> !AnOibit for Foo<T> where T: Sync"
21+
// @has impl_parts/trait.AnOibit.html '//*[@class="item-list"]//code' \
22+
// "impl<T: Clone> !AnOibit for Foo<T> where T: Sync"
23+
impl<T: Clone> !AnOibit for Foo<T> where T: Sync {}

0 commit comments

Comments
 (0)