Skip to content

Commit

Permalink
Auto merge of rust-lang#51885 - GuillaumeGomez:trait-impl-show-docs, …
Browse files Browse the repository at this point in the history
…r=Mark-Simulacrum,QuietMisdreavus

Trait impl show docs

Fixes rust-lang#51834.

<img width="1440" alt="screen shot 2018-06-29 at 00 14 33" src="https://user-images.githubusercontent.com/3050060/42063323-6e6e8cc8-7b31-11e8-88ef-4dd2229df76c.png">

(You can see both commit changes in the screenshot 😄)

r? @QuietMisdreavus
  • Loading branch information
bors committed Sep 8, 2018
2 parents 295ad30 + d540914 commit 06da917
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 97 deletions.
10 changes: 3 additions & 7 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
///
/// This will decrement the strong reference count. If the strong reference
/// count reaches zero then the only other references (if any) are
/// [`Weak`][weak], so we `drop` the inner value.
///
/// [weak]: struct.Weak.html
/// [`Weak`], so we `drop` the inner value.
///
/// # Examples
///
Expand Down Expand Up @@ -1173,9 +1171,8 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Weak<U>> for Weak<T> {}

impl<T> Weak<T> {
/// Constructs a new `Weak<T>`, without allocating any memory.
/// Calling [`upgrade`] on the return value always gives [`None`].
/// Calling [`upgrade`][Weak::upgrade] on the return value always gives [`None`].
///
/// [`upgrade`]: struct.Weak.html#method.upgrade
/// [`None`]: ../../std/option/enum.Option.html
///
/// # Examples
Expand Down Expand Up @@ -1321,9 +1318,8 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> {
#[stable(feature = "downgraded_weak", since = "1.10.0")]
impl<T> Default for Weak<T> {
/// Constructs a new `Weak<T>`, allocating memory for `T` without initializing
/// it. Calling [`upgrade`] on the return value always gives [`None`].
/// it. Calling [`upgrade`][Weak::upgrade] on the return value always gives [`None`].
///
/// [`upgrade`]: struct.Weak.html#method.upgrade
/// [`None`]: ../../std/option/enum.Option.html
///
/// # Examples
Expand Down
4 changes: 1 addition & 3 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1927,9 +1927,7 @@ impl<'a> Add<&'a str> for String {

/// Implements the `+=` operator for appending to a `String`.
///
/// This has the same behavior as the [`push_str`] method.
///
/// [`push_str`]: struct.String.html#method.push_str
/// This has the same behavior as the [`push_str`][String::push_str] method.
#[stable(feature = "stringaddassign", since = "1.12.0")]
impl<'a> AddAssign<&'a str> for String {
#[inline]
Expand Down
8 changes: 3 additions & 5 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
///
/// This will decrement the strong reference count. If the strong reference
/// count reaches zero then the only other references (if any) are
/// [`Weak`][weak], so we `drop` the inner value.
///
/// [weak]: struct.Weak.html
/// [`Weak`], so we `drop` the inner value.
///
/// # Examples
///
Expand Down Expand Up @@ -1159,9 +1157,9 @@ impl<T: ?Sized> Clone for Weak<T> {
#[stable(feature = "downgraded_weak", since = "1.10.0")]
impl<T> Default for Weak<T> {
/// Constructs a new `Weak<T>`, without allocating memory.
/// Calling [`upgrade`] on the return value always gives [`None`].
/// Calling [`upgrade`][Weak::upgrade] on the return value always
/// gives [`None`].
///
/// [`upgrade`]: struct.Weak.html#method.upgrade
/// [`None`]: ../../std/option/enum.Option.html#variant.None
///
/// # Examples
Expand Down
12 changes: 5 additions & 7 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,9 +1006,7 @@ fn expect_failed(msg: &str) -> ! {

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Option<T> {
/// Returns [`None`].
///
/// [`None`]: #variant.None
/// Returns [`None`][Option::None].
#[inline]
fn default() -> Option<T> { None }
}
Expand Down Expand Up @@ -1228,9 +1226,10 @@ unsafe impl<A> TrustedLen for IntoIter<A> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
/// Takes each element in the [`Iterator`]: if it is [`None`], no further
/// elements are taken, and the [`None`] is returned. Should no [`None`] occur, a
/// container with the values of each `Option` is returned.
/// Takes each element in the [`Iterator`]: if it is [`None`][Option::None],
/// no further elements are taken, and the [`None`][Option::None] is
/// returned. Should no [`None`][Option::None] occur, a container with the
/// values of each [`Option`] is returned.
///
/// Here is an example which increments every integer in a vector,
/// checking for overflow:
Expand All @@ -1247,7 +1246,6 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
/// ```
///
/// [`Iterator`]: ../iter/trait.Iterator.html
/// [`None`]: enum.Option.html#variant.None
#[inline]
fn from_iter<I: IntoIterator<Item=Option<A>>>(iter: I) -> Option<V> {
// FIXME(#11084): This could be replaced with Iterator::scan when this
Expand Down
12 changes: 3 additions & 9 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ impl<T, E> Result<T, E> {

/// Returns an iterator over the possibly contained value.
///
/// The iterator yields one value if the result is [`Ok`], otherwise none.
/// The iterator yields one value if the result is [`Result::Ok`], otherwise none.
///
/// # Examples
///
Expand All @@ -520,8 +520,6 @@ impl<T, E> Result<T, E> {
/// let x: Result<u32, &str> = Err("nothing!");
/// assert_eq!(x.iter().next(), None);
/// ```
///
/// [`Ok`]: enum.Result.html#variant.Ok
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
Expand All @@ -530,7 +528,7 @@ impl<T, E> Result<T, E> {

/// Returns a mutable iterator over the possibly contained value.
///
/// The iterator yields one value if the result is [`Ok`], otherwise none.
/// The iterator yields one value if the result is [`Result::Ok`], otherwise none.
///
/// # Examples
///
Expand All @@ -547,8 +545,6 @@ impl<T, E> Result<T, E> {
/// let mut x: Result<u32, &str> = Err("nothing!");
/// assert_eq!(x.iter_mut().next(), None);
/// ```
///
/// [`Ok`]: enum.Result.html#variant.Ok
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut(&mut self) -> IterMut<T> {
Expand Down Expand Up @@ -994,7 +990,7 @@ impl<T, E> IntoIterator for Result<T, E> {

/// Returns a consuming iterator over the possibly contained value.
///
/// The iterator yields one value if the result is [`Ok`], otherwise none.
/// The iterator yields one value if the result is [`Result::Ok`], otherwise none.
///
/// # Examples
///
Expand All @@ -1009,8 +1005,6 @@ impl<T, E> IntoIterator for Result<T, E> {
/// let v: Vec<u32> = x.into_iter().collect();
/// assert_eq!(v, []);
/// ```
///
/// [`Ok`]: enum.Result.html#variant.Ok
#[inline]
fn into_iter(self) -> IntoIter<T> {
IntoIter { inner: self.ok() }
Expand Down
71 changes: 33 additions & 38 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2678,7 +2678,6 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,

fn render_implementor(cx: &Context, implementor: &Impl, w: &mut fmt::Formatter,
implementor_dups: &FxHashMap<&str, (DefId, bool)>) -> fmt::Result {
write!(w, "<li><table class='table-display'><tbody><tr><td><code>")?;
// If there's already another implementor that has the same abbridged name, use the
// full path, for example in `std::iter::ExactSizeIterator`
let use_absolute = match implementor.inner_impl().for_ {
Expand All @@ -2689,22 +2688,8 @@ fn render_implementor(cx: &Context, implementor: &Impl, w: &mut fmt::Formatter,
} => implementor_dups[path.last_name()].1,
_ => false,
};
fmt_impl_for_trait_page(&implementor.inner_impl(), w, use_absolute)?;
for it in &implementor.inner_impl().items {
if let clean::TypedefItem(ref tydef, _) = it.inner {
write!(w, "<span class=\"where fmt-newline\"> ")?;
assoc_type(w, it, &[], Some(&tydef.type_), AssocItemLink::Anchor(None))?;
write!(w, ";</span>")?;
}
}
write!(w, "</code><td>")?;
if let Some(l) = (Item { cx, item: &implementor.impl_item }).src_href() {
write!(w, "<div class='out-of-band'>")?;
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
l, "goto source code")?;
write!(w, "</div>")?;
}
writeln!(w, "</td></tr></tbody></table></li>")?;
render_impl(w, cx, implementor, AssocItemLink::Anchor(None), RenderMode::Normal,
implementor.impl_item.stable_since(), false, Some(use_absolute))?;
Ok(())
}

Expand All @@ -2715,7 +2700,7 @@ fn render_impls(cx: &Context, w: &mut fmt::Formatter,
let did = i.trait_did().unwrap();
let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods);
render_impl(w, cx, i, assoc_link,
RenderMode::Normal, containing_item.stable_since(), true)?;
RenderMode::Normal, containing_item.stable_since(), true, None)?;
}
Ok(())
}
Expand Down Expand Up @@ -2907,14 +2892,14 @@ fn item_trait(
<h2 id='implementors' class='small-section-header'>\
Implementors<a href='#implementors' class='anchor'></a>\
</h2>\
<ul class='item-list' id='implementors-list'>\
<div class='item-list' id='implementors-list'>\
";

let synthetic_impl_header = "\
<h2 id='synthetic-implementors' class='small-section-header'>\
Auto implementors<a href='#synthetic-implementors' class='anchor'></a>\
</h2>\
<ul class='item-list' id='synthetic-implementors-list'>\
<div class='item-list' id='synthetic-implementors-list'>\
";

let mut synthetic_types = Vec::new();
Expand Down Expand Up @@ -2964,7 +2949,8 @@ fn item_trait(
&implementor.inner_impl().provided_trait_methods
);
render_impl(w, cx, &implementor, assoc_link,
RenderMode::Normal, implementor.impl_item.stable_since(), false)?;
RenderMode::Normal, implementor.impl_item.stable_since(), false,
None)?;
}
}
}
Expand All @@ -2973,7 +2959,7 @@ fn item_trait(
for implementor in concrete {
render_implementor(cx, implementor, w, &implementor_dups)?;
}
write!(w, "</ul>")?;
write!(w, "</div>")?;

if t.auto {
write!(w, "{}", synthetic_impl_header)?;
Expand All @@ -2983,17 +2969,17 @@ fn item_trait(
);
render_implementor(cx, implementor, w, &implementor_dups)?;
}
write!(w, "</ul>")?;
write!(w, "</div>")?;
}
} else {
// even without any implementations to write in, we still want the heading and list, so the
// implementors javascript file pulled in below has somewhere to write the impls into
write!(w, "{}", impl_header)?;
write!(w, "</ul>")?;
write!(w, "</div>")?;

if t.auto {
write!(w, "{}", synthetic_impl_header)?;
write!(w, "</ul>")?;
write!(w, "</div>")?;
}
}
write!(w, r#"<script type="text/javascript">window.inlined_types=new Set({});</script>"#,
Expand Down Expand Up @@ -3616,7 +3602,7 @@ fn render_assoc_items(w: &mut fmt::Formatter,
};
for i in &non_trait {
render_impl(w, cx, i, AssocItemLink::Anchor(None), render_mode,
containing_item.stable_since(), true)?;
containing_item.stable_since(), true, None)?;
}
}
if let AssocItemRender::DerefFor { .. } = what {
Expand Down Expand Up @@ -3797,15 +3783,32 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {

fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLink,
render_mode: RenderMode, outer_version: Option<&str>,
show_def_docs: bool) -> fmt::Result {
show_def_docs: bool, use_absolute: Option<bool>) -> fmt::Result {
if render_mode == RenderMode::Normal {
let id = cx.derive_id(match i.inner_impl().trait_ {
Some(ref t) => format!("impl-{}", small_url_encode(&format!("{:#}", t))),
None => "impl".to_string(),
});
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
<tbody><tr><td><code>{}</code>",
id, i.inner_impl())?;
if let Some(use_absolute) = use_absolute {
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
<tbody><tr><td><code>", id)?;
fmt_impl_for_trait_page(&i.inner_impl(), w, use_absolute)?;
if show_def_docs {
for it in &i.inner_impl().items {
if let clean::TypedefItem(ref tydef, _) = it.inner {
write!(w, "<span class=\"where fmt-newline\"> ")?;
assoc_type(w, it, &vec![], Some(&tydef.type_),
AssocItemLink::Anchor(None))?;
write!(w, ";</span>")?;
}
}
}
write!(w, "</code>")?;
} else {
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
<tbody><tr><td><code>{}</code>",
id, i.inner_impl())?;
}
write!(w, "<a href='#{}' class='anchor'></a>", id)?;
write!(w, "</span></td><td><span class='out-of-band'>")?;
let since = i.impl_item.stability.as_ref().map(|s| &s.since[..]);
Expand Down Expand Up @@ -3929,10 +3932,6 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
let traits = &cache().traits;
let trait_ = i.trait_did().map(|did| &traits[&did]);

if !show_def_docs {
write!(w, "<span class='docblock autohide'>")?;
}

write!(w, "<div class='impl-items'>")?;
for trait_item in &i.inner_impl().items {
doc_impl_item(w, cx, trait_item, link, render_mode,
Expand Down Expand Up @@ -3968,10 +3967,6 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
}
write!(w, "</div>")?;

if !show_def_docs {
write!(w, "</span>")?;
}

Ok(())
}

Expand Down
9 changes: 6 additions & 3 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1791,9 +1791,12 @@
x[k].setAttribute('href', rootPath + href);
}
}
var li = document.createElement('li');
li.appendChild(code);
list.appendChild(li);
var display = document.createElement('h3');
addClass(display, "impl");
display.innerHTML = '<span class="in-band"><table class="table-display"><tbody>\
<tr><td><code>' + code.outerHTML + '</code></td><td></td></tr></tbody></table>\
</span>';
list.appendChild(display);
}
}
};
Expand Down
24 changes: 15 additions & 9 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ h3.impl, h3.method, h3.type {

h1, h2, h3, h4,
.sidebar, a.source, .search-input, .content table :not(code)>a,
.collapse-toggle, ul.item-list > li > .out-of-band {
.collapse-toggle, div.item-list .out-of-band {
font-family: "Fira Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

Expand Down Expand Up @@ -367,10 +367,6 @@ h4.method > .out-of-band {
font-size: 19px;
}

ul.item-list > li > .out-of-band {
font-size: 19px;
}

h4 > code, h3 > code, .invisible > code {
max-width: calc(100% - 41px);
display: block;
Expand Down Expand Up @@ -436,10 +432,6 @@ h4 > code, h3 > code, .invisible > code {
padding: 0;
}

.content .item-list li {
margin-bottom: 1em;
}

.content .multi-column {
-moz-column-count: 5;
-moz-column-gap: 2.5em;
Expand Down Expand Up @@ -473,6 +465,11 @@ h4 > code, h3 > code, .invisible > code {
.content .impl-items .docblock, .content .impl-items .stability {
margin-bottom: .6em;
}

.content .impl-items > .stability {
margin-left: 40px;
}

.content .docblock > .impl-items {
margin-left: 20px;
margin-top: -34px;
Expand Down Expand Up @@ -1363,6 +1360,15 @@ kbd {
font-size: 19px;
display: block;
}
#implementors-list > .impl-items .table-display .out-of-band {
font-size: 17px;
}

.table-display td:hover .anchor {
display: block;
top: 2px;
left: -5px;
}

#main > ul {
padding-left: 10px;
Expand Down
Loading

0 comments on commit 06da917

Please sign in to comment.