Skip to content

Commit 06da917

Browse files
committed
Auto merge of #51885 - GuillaumeGomez:trait-impl-show-docs, r=Mark-Simulacrum,QuietMisdreavus
Trait impl show docs Fixes #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
2 parents 295ad30 + d540914 commit 06da917

File tree

15 files changed

+77
-97
lines changed

15 files changed

+77
-97
lines changed

src/liballoc/rc.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
806806
///
807807
/// This will decrement the strong reference count. If the strong reference
808808
/// count reaches zero then the only other references (if any) are
809-
/// [`Weak`][weak], so we `drop` the inner value.
810-
///
811-
/// [weak]: struct.Weak.html
809+
/// [`Weak`], so we `drop` the inner value.
812810
///
813811
/// # Examples
814812
///
@@ -1173,9 +1171,8 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Weak<U>> for Weak<T> {}
11731171

11741172
impl<T> Weak<T> {
11751173
/// Constructs a new `Weak<T>`, without allocating any memory.
1176-
/// Calling [`upgrade`] on the return value always gives [`None`].
1174+
/// Calling [`upgrade`][Weak::upgrade] on the return value always gives [`None`].
11771175
///
1178-
/// [`upgrade`]: struct.Weak.html#method.upgrade
11791176
/// [`None`]: ../../std/option/enum.Option.html
11801177
///
11811178
/// # Examples
@@ -1321,9 +1318,8 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> {
13211318
#[stable(feature = "downgraded_weak", since = "1.10.0")]
13221319
impl<T> Default for Weak<T> {
13231320
/// Constructs a new `Weak<T>`, allocating memory for `T` without initializing
1324-
/// it. Calling [`upgrade`] on the return value always gives [`None`].
1321+
/// it. Calling [`upgrade`][Weak::upgrade] on the return value always gives [`None`].
13251322
///
1326-
/// [`upgrade`]: struct.Weak.html#method.upgrade
13271323
/// [`None`]: ../../std/option/enum.Option.html
13281324
///
13291325
/// # Examples

src/liballoc/string.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1927,9 +1927,7 @@ impl<'a> Add<&'a str> for String {
19271927

19281928
/// Implements the `+=` operator for appending to a `String`.
19291929
///
1930-
/// This has the same behavior as the [`push_str`] method.
1931-
///
1932-
/// [`push_str`]: struct.String.html#method.push_str
1930+
/// This has the same behavior as the [`push_str`][String::push_str] method.
19331931
#[stable(feature = "stringaddassign", since = "1.12.0")]
19341932
impl<'a> AddAssign<&'a str> for String {
19351933
#[inline]

src/liballoc/sync.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -916,9 +916,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
916916
///
917917
/// This will decrement the strong reference count. If the strong reference
918918
/// count reaches zero then the only other references (if any) are
919-
/// [`Weak`][weak], so we `drop` the inner value.
920-
///
921-
/// [weak]: struct.Weak.html
919+
/// [`Weak`], so we `drop` the inner value.
922920
///
923921
/// # Examples
924922
///
@@ -1159,9 +1157,9 @@ impl<T: ?Sized> Clone for Weak<T> {
11591157
#[stable(feature = "downgraded_weak", since = "1.10.0")]
11601158
impl<T> Default for Weak<T> {
11611159
/// Constructs a new `Weak<T>`, without allocating memory.
1162-
/// Calling [`upgrade`] on the return value always gives [`None`].
1160+
/// Calling [`upgrade`][Weak::upgrade] on the return value always
1161+
/// gives [`None`].
11631162
///
1164-
/// [`upgrade`]: struct.Weak.html#method.upgrade
11651163
/// [`None`]: ../../std/option/enum.Option.html#variant.None
11661164
///
11671165
/// # Examples

src/libcore/option.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1006,9 +1006,7 @@ fn expect_failed(msg: &str) -> ! {
10061006

10071007
#[stable(feature = "rust1", since = "1.0.0")]
10081008
impl<T> Default for Option<T> {
1009-
/// Returns [`None`].
1010-
///
1011-
/// [`None`]: #variant.None
1009+
/// Returns [`None`][Option::None].
10121010
#[inline]
10131011
fn default() -> Option<T> { None }
10141012
}
@@ -1228,9 +1226,10 @@ unsafe impl<A> TrustedLen for IntoIter<A> {}
12281226

12291227
#[stable(feature = "rust1", since = "1.0.0")]
12301228
impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
1231-
/// Takes each element in the [`Iterator`]: if it is [`None`], no further
1232-
/// elements are taken, and the [`None`] is returned. Should no [`None`] occur, a
1233-
/// container with the values of each `Option` is returned.
1229+
/// Takes each element in the [`Iterator`]: if it is [`None`][Option::None],
1230+
/// no further elements are taken, and the [`None`][Option::None] is
1231+
/// returned. Should no [`None`][Option::None] occur, a container with the
1232+
/// values of each [`Option`] is returned.
12341233
///
12351234
/// Here is an example which increments every integer in a vector,
12361235
/// checking for overflow:
@@ -1247,7 +1246,6 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
12471246
/// ```
12481247
///
12491248
/// [`Iterator`]: ../iter/trait.Iterator.html
1250-
/// [`None`]: enum.Option.html#variant.None
12511249
#[inline]
12521250
fn from_iter<I: IntoIterator<Item=Option<A>>>(iter: I) -> Option<V> {
12531251
// FIXME(#11084): This could be replaced with Iterator::scan when this

src/libcore/result.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl<T, E> Result<T, E> {
507507

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

531529
/// Returns a mutable iterator over the possibly contained value.
532530
///
533-
/// The iterator yields one value if the result is [`Ok`], otherwise none.
531+
/// The iterator yields one value if the result is [`Result::Ok`], otherwise none.
534532
///
535533
/// # Examples
536534
///
@@ -547,8 +545,6 @@ impl<T, E> Result<T, E> {
547545
/// let mut x: Result<u32, &str> = Err("nothing!");
548546
/// assert_eq!(x.iter_mut().next(), None);
549547
/// ```
550-
///
551-
/// [`Ok`]: enum.Result.html#variant.Ok
552548
#[inline]
553549
#[stable(feature = "rust1", since = "1.0.0")]
554550
pub fn iter_mut(&mut self) -> IterMut<T> {
@@ -994,7 +990,7 @@ impl<T, E> IntoIterator for Result<T, E> {
994990

995991
/// Returns a consuming iterator over the possibly contained value.
996992
///
997-
/// The iterator yields one value if the result is [`Ok`], otherwise none.
993+
/// The iterator yields one value if the result is [`Result::Ok`], otherwise none.
998994
///
999995
/// # Examples
1000996
///
@@ -1009,8 +1005,6 @@ impl<T, E> IntoIterator for Result<T, E> {
10091005
/// let v: Vec<u32> = x.into_iter().collect();
10101006
/// assert_eq!(v, []);
10111007
/// ```
1012-
///
1013-
/// [`Ok`]: enum.Result.html#variant.Ok
10141008
#[inline]
10151009
fn into_iter(self) -> IntoIter<T> {
10161010
IntoIter { inner: self.ok() }

src/librustdoc/html/render.rs

+33-38
Original file line numberDiff line numberDiff line change
@@ -2678,7 +2678,6 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
26782678

26792679
fn render_implementor(cx: &Context, implementor: &Impl, w: &mut fmt::Formatter,
26802680
implementor_dups: &FxHashMap<&str, (DefId, bool)>) -> fmt::Result {
2681-
write!(w, "<li><table class='table-display'><tbody><tr><td><code>")?;
26822681
// If there's already another implementor that has the same abbridged name, use the
26832682
// full path, for example in `std::iter::ExactSizeIterator`
26842683
let use_absolute = match implementor.inner_impl().for_ {
@@ -2689,22 +2688,8 @@ fn render_implementor(cx: &Context, implementor: &Impl, w: &mut fmt::Formatter,
26892688
} => implementor_dups[path.last_name()].1,
26902689
_ => false,
26912690
};
2692-
fmt_impl_for_trait_page(&implementor.inner_impl(), w, use_absolute)?;
2693-
for it in &implementor.inner_impl().items {
2694-
if let clean::TypedefItem(ref tydef, _) = it.inner {
2695-
write!(w, "<span class=\"where fmt-newline\"> ")?;
2696-
assoc_type(w, it, &[], Some(&tydef.type_), AssocItemLink::Anchor(None))?;
2697-
write!(w, ";</span>")?;
2698-
}
2699-
}
2700-
write!(w, "</code><td>")?;
2701-
if let Some(l) = (Item { cx, item: &implementor.impl_item }).src_href() {
2702-
write!(w, "<div class='out-of-band'>")?;
2703-
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
2704-
l, "goto source code")?;
2705-
write!(w, "</div>")?;
2706-
}
2707-
writeln!(w, "</td></tr></tbody></table></li>")?;
2691+
render_impl(w, cx, implementor, AssocItemLink::Anchor(None), RenderMode::Normal,
2692+
implementor.impl_item.stable_since(), false, Some(use_absolute))?;
27082693
Ok(())
27092694
}
27102695

@@ -2715,7 +2700,7 @@ fn render_impls(cx: &Context, w: &mut fmt::Formatter,
27152700
let did = i.trait_did().unwrap();
27162701
let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods);
27172702
render_impl(w, cx, i, assoc_link,
2718-
RenderMode::Normal, containing_item.stable_since(), true)?;
2703+
RenderMode::Normal, containing_item.stable_since(), true, None)?;
27192704
}
27202705
Ok(())
27212706
}
@@ -2907,14 +2892,14 @@ fn item_trait(
29072892
<h2 id='implementors' class='small-section-header'>\
29082893
Implementors<a href='#implementors' class='anchor'></a>\
29092894
</h2>\
2910-
<ul class='item-list' id='implementors-list'>\
2895+
<div class='item-list' id='implementors-list'>\
29112896
";
29122897

29132898
let synthetic_impl_header = "\
29142899
<h2 id='synthetic-implementors' class='small-section-header'>\
29152900
Auto implementors<a href='#synthetic-implementors' class='anchor'></a>\
29162901
</h2>\
2917-
<ul class='item-list' id='synthetic-implementors-list'>\
2902+
<div class='item-list' id='synthetic-implementors-list'>\
29182903
";
29192904

29202905
let mut synthetic_types = Vec::new();
@@ -2964,7 +2949,8 @@ fn item_trait(
29642949
&implementor.inner_impl().provided_trait_methods
29652950
);
29662951
render_impl(w, cx, &implementor, assoc_link,
2967-
RenderMode::Normal, implementor.impl_item.stable_since(), false)?;
2952+
RenderMode::Normal, implementor.impl_item.stable_since(), false,
2953+
None)?;
29682954
}
29692955
}
29702956
}
@@ -2973,7 +2959,7 @@ fn item_trait(
29732959
for implementor in concrete {
29742960
render_implementor(cx, implementor, w, &implementor_dups)?;
29752961
}
2976-
write!(w, "</ul>")?;
2962+
write!(w, "</div>")?;
29772963

29782964
if t.auto {
29792965
write!(w, "{}", synthetic_impl_header)?;
@@ -2983,17 +2969,17 @@ fn item_trait(
29832969
);
29842970
render_implementor(cx, implementor, w, &implementor_dups)?;
29852971
}
2986-
write!(w, "</ul>")?;
2972+
write!(w, "</div>")?;
29872973
}
29882974
} else {
29892975
// even without any implementations to write in, we still want the heading and list, so the
29902976
// implementors javascript file pulled in below has somewhere to write the impls into
29912977
write!(w, "{}", impl_header)?;
2992-
write!(w, "</ul>")?;
2978+
write!(w, "</div>")?;
29932979

29942980
if t.auto {
29952981
write!(w, "{}", synthetic_impl_header)?;
2996-
write!(w, "</ul>")?;
2982+
write!(w, "</div>")?;
29972983
}
29982984
}
29992985
write!(w, r#"<script type="text/javascript">window.inlined_types=new Set({});</script>"#,
@@ -3616,7 +3602,7 @@ fn render_assoc_items(w: &mut fmt::Formatter,
36163602
};
36173603
for i in &non_trait {
36183604
render_impl(w, cx, i, AssocItemLink::Anchor(None), render_mode,
3619-
containing_item.stable_since(), true)?;
3605+
containing_item.stable_since(), true, None)?;
36203606
}
36213607
}
36223608
if let AssocItemRender::DerefFor { .. } = what {
@@ -3797,15 +3783,32 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
37973783

37983784
fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLink,
37993785
render_mode: RenderMode, outer_version: Option<&str>,
3800-
show_def_docs: bool) -> fmt::Result {
3786+
show_def_docs: bool, use_absolute: Option<bool>) -> fmt::Result {
38013787
if render_mode == RenderMode::Normal {
38023788
let id = cx.derive_id(match i.inner_impl().trait_ {
38033789
Some(ref t) => format!("impl-{}", small_url_encode(&format!("{:#}", t))),
38043790
None => "impl".to_string(),
38053791
});
3806-
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
3807-
<tbody><tr><td><code>{}</code>",
3808-
id, i.inner_impl())?;
3792+
if let Some(use_absolute) = use_absolute {
3793+
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
3794+
<tbody><tr><td><code>", id)?;
3795+
fmt_impl_for_trait_page(&i.inner_impl(), w, use_absolute)?;
3796+
if show_def_docs {
3797+
for it in &i.inner_impl().items {
3798+
if let clean::TypedefItem(ref tydef, _) = it.inner {
3799+
write!(w, "<span class=\"where fmt-newline\"> ")?;
3800+
assoc_type(w, it, &vec![], Some(&tydef.type_),
3801+
AssocItemLink::Anchor(None))?;
3802+
write!(w, ";</span>")?;
3803+
}
3804+
}
3805+
}
3806+
write!(w, "</code>")?;
3807+
} else {
3808+
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
3809+
<tbody><tr><td><code>{}</code>",
3810+
id, i.inner_impl())?;
3811+
}
38093812
write!(w, "<a href='#{}' class='anchor'></a>", id)?;
38103813
write!(w, "</span></td><td><span class='out-of-band'>")?;
38113814
let since = i.impl_item.stability.as_ref().map(|s| &s.since[..]);
@@ -3929,10 +3932,6 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
39293932
let traits = &cache().traits;
39303933
let trait_ = i.trait_did().map(|did| &traits[&did]);
39313934

3932-
if !show_def_docs {
3933-
write!(w, "<span class='docblock autohide'>")?;
3934-
}
3935-
39363935
write!(w, "<div class='impl-items'>")?;
39373936
for trait_item in &i.inner_impl().items {
39383937
doc_impl_item(w, cx, trait_item, link, render_mode,
@@ -3968,10 +3967,6 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
39683967
}
39693968
write!(w, "</div>")?;
39703969

3971-
if !show_def_docs {
3972-
write!(w, "</span>")?;
3973-
}
3974-
39753970
Ok(())
39763971
}
39773972

src/librustdoc/html/static/main.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1791,9 +1791,12 @@
17911791
x[k].setAttribute('href', rootPath + href);
17921792
}
17931793
}
1794-
var li = document.createElement('li');
1795-
li.appendChild(code);
1796-
list.appendChild(li);
1794+
var display = document.createElement('h3');
1795+
addClass(display, "impl");
1796+
display.innerHTML = '<span class="in-band"><table class="table-display"><tbody>\
1797+
<tr><td><code>' + code.outerHTML + '</code></td><td></td></tr></tbody></table>\
1798+
</span>';
1799+
list.appendChild(display);
17971800
}
17981801
}
17991802
};

src/librustdoc/html/static/rustdoc.css

+15-9
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ h3.impl, h3.method, h3.type {
114114

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

@@ -367,10 +367,6 @@ h4.method > .out-of-band {
367367
font-size: 19px;
368368
}
369369

370-
ul.item-list > li > .out-of-band {
371-
font-size: 19px;
372-
}
373-
374370
h4 > code, h3 > code, .invisible > code {
375371
max-width: calc(100% - 41px);
376372
display: block;
@@ -436,10 +432,6 @@ h4 > code, h3 > code, .invisible > code {
436432
padding: 0;
437433
}
438434

439-
.content .item-list li {
440-
margin-bottom: 1em;
441-
}
442-
443435
.content .multi-column {
444436
-moz-column-count: 5;
445437
-moz-column-gap: 2.5em;
@@ -473,6 +465,11 @@ h4 > code, h3 > code, .invisible > code {
473465
.content .impl-items .docblock, .content .impl-items .stability {
474466
margin-bottom: .6em;
475467
}
468+
469+
.content .impl-items > .stability {
470+
margin-left: 40px;
471+
}
472+
476473
.content .docblock > .impl-items {
477474
margin-left: 20px;
478475
margin-top: -34px;
@@ -1363,6 +1360,15 @@ kbd {
13631360
font-size: 19px;
13641361
display: block;
13651362
}
1363+
#implementors-list > .impl-items .table-display .out-of-band {
1364+
font-size: 17px;
1365+
}
1366+
1367+
.table-display td:hover .anchor {
1368+
display: block;
1369+
top: 2px;
1370+
left: -5px;
1371+
}
13661372

13671373
#main > ul {
13681374
padding-left: 10px;

0 commit comments

Comments
 (0)