Skip to content

Commit 6d00124

Browse files
authored
Rollup merge of rust-lang#56874 - JohnHeitmann:docs-spacing, r=GuillaumeGomez
Simplify foreign type rendering. Simplified foreign type rendering by switching from tables to flexbox. Also, removed some seemingly extraneous elements like “ghost” spans. Reduces element count on the `std::iter::Iterator` page by 30%. On my laptop it drops Iterator page load time from ~15s to ~10s. Frame times during scrolling are a hair lower too. Known visual changes (happy to tweak based on feedback): * The main `impl ...` headers are now getting the default, larger, h3 font size. This was an accident, but I liked how it turned out so I didn't fix it. * There's a hair less vertical spacing between the end of a where block and the start of the next fn. Now, all spacing is consistent. I think this looks a bit worse. I may tweak vertical spacing more here or in a follow-up that cleans up vertical spacing more broadly. * "[src]" links are all sized at 17px. A few were 19px in the original. I haven't yet done heavy cross-browser or cross-crate testing. I was hoping to get a quick thumbs up or thumbs down here at this first draft, then if this is on the right track I'll spend some time on that testing. TODO: - [x] Test on Chrome - [x] Test on Firefox - [ ] ~~Test on UC Android~~ - [x] Test on Edge - [x] Test on iOS safari - [x] Test on desktop safari - [x] Update automated tests - [x] Increase vertical margin - [x] Fix "Important traits for" hover overlap - [x] Wait for rust-lang#55798 to land & merge it
2 parents 2cf736f + 34bd2b8 commit 6d00124

19 files changed

+95
-93
lines changed

src/librustdoc/html/render.rs

+19-51
Original file line numberDiff line numberDiff line change
@@ -3059,7 +3059,7 @@ fn item_trait(
30593059
let item_type = m.type_();
30603060
let id = cx.derive_id(format!("{}.{}", item_type, name));
30613061
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
3062-
write!(w, "{extra}<h3 id='{id}' class='method'><code id='{ns_id}'>",
3062+
write!(w, "<h3 id='{id}' class='method'>{extra}<code id='{ns_id}'>",
30633063
extra = render_spotlight_traits(m)?,
30643064
id = id,
30653065
ns_id = ns_id)?;
@@ -3444,7 +3444,7 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
34443444
let id = format!("{}.{}", ItemType::StructField, name);
34453445
write!(w, "<span id=\"{id}\" class=\"{shortty} small-section-header\">\
34463446
<a href=\"#{id}\" class=\"anchor field\"></a>\
3447-
<span class='invisible'><code>{name}: {ty}</code></span>\
3447+
<code>{name}: {ty}</code>\
34483448
</span>",
34493449
id = id,
34503450
name = name,
@@ -3999,8 +3999,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
39993999
None => "impl".to_string(),
40004000
});
40014001
if let Some(use_absolute) = use_absolute {
4002-
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
4003-
<tbody><tr><td><code>", id)?;
4002+
write!(w, "<h3 id='{}' class='impl'><code class='in-band'>", id)?;
40044003
fmt_impl_for_trait_page(&i.inner_impl(), w, use_absolute)?;
40054004
if show_def_docs {
40064005
for it in &i.inner_impl().items {
@@ -4014,22 +4013,18 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
40144013
}
40154014
write!(w, "</code>")?;
40164015
} else {
4017-
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
4018-
<tbody><tr><td><code>{}</code>",
4019-
id, i.inner_impl())?;
4016+
write!(w, "<h3 id='{}' class='impl'><code class='in-band'>{}</code>",
4017+
id, i.inner_impl()
4018+
)?;
40204019
}
40214020
write!(w, "<a href='#{}' class='anchor'></a>", id)?;
4022-
write!(w, "</td><td><span class='out-of-band'>")?;
40234021
let since = i.impl_item.stability.as_ref().map(|s| &s.since[..]);
4022+
render_stability_since_raw(w, since, outer_version)?;
40244023
if let Some(l) = (Item { item: &i.impl_item, cx: cx }).src_href() {
4025-
write!(w, "<div class='ghost'></div>")?;
4026-
render_stability_since_raw(w, since, outer_version)?;
40274024
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
40284025
l, "goto source code")?;
4029-
} else {
4030-
render_stability_since_raw(w, since, outer_version)?;
40314026
}
4032-
write!(w, "</span></td></tr></tbody></table></span></h3>")?;
4027+
write!(w, "</h3>")?;
40334028
if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) {
40344029
let mut ids = cx.id_map.borrow_mut();
40354030
write!(w, "<div class='docblock'>{}</div>",
@@ -4065,20 +4060,15 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
40654060
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
40664061
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class)?;
40674062
write!(w, "{}", spotlight_decl(decl)?)?;
4068-
write!(w, "<table id='{}' class='table-display'><tbody><tr><td><code>", ns_id)?;
4063+
write!(w, "<code id='{}'>", ns_id)?;
40694064
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl)?;
40704065
write!(w, "</code>")?;
4066+
render_stability_since_raw(w, item.stable_since(), outer_version)?;
40714067
if let Some(l) = (Item { cx, item }).src_href() {
4072-
write!(w, "</td><td><span class='out-of-band'>")?;
4073-
write!(w, "<div class='ghost'></div>")?;
4074-
render_stability_since_raw(w, item.stable_since(), outer_version)?;
4075-
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a></span>",
4068+
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
40764069
l, "goto source code")?;
4077-
} else {
4078-
write!(w, "</td><td>")?;
4079-
render_stability_since_raw(w, item.stable_since(), outer_version)?;
40804070
}
4081-
write!(w, "</td></tr></tbody></table></h4>")?;
4071+
write!(w, "</h4>")?;
40824072
}
40834073
}
40844074
clean::TypedefItem(ref tydef, _) => {
@@ -4090,40 +4080,18 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
40904080
write!(w, "</code></h4>")?;
40914081
}
40924082
clean::AssociatedConstItem(ref ty, ref default) => {
4093-
let mut version = String::new();
4094-
4095-
render_stability_since_raw(&mut version, item.stable_since(), outer_version)?;
4096-
40974083
let id = cx.derive_id(format!("{}.{}", item_type, name));
40984084
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
40994085
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class)?;
4100-
if !version.is_empty() {
4101-
write!(w, "<table id='{}' class='table-display'><tbody><tr><td><code>", ns_id)?;
4102-
} else {
4103-
write!(w, "<code id='{}'>", ns_id)?;
4104-
}
4086+
write!(w, "<code id='{}'>", ns_id)?;
41054087
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id))?;
4106-
if !version.is_empty() {
4107-
write!(w, "</code>")?;
4108-
}
4109-
let src = if let Some(l) = (Item { cx, item }).src_href() {
4110-
if !version.is_empty() {
4111-
write!(w, "</td><td><span class='out-of-band'>")?;
4112-
write!(w, "<div class='ghost'></div>{}", version)?;
4113-
}
4114-
format!("<a class='srclink' href='{}' title='{}'>[src]</a>",
4115-
l, "goto source code")
4116-
} else {
4117-
if !version.is_empty() {
4118-
write!(w, "</td><td>{}", version)?;
4119-
}
4120-
String::new()
4121-
};
4122-
if version.is_empty() {
4123-
write!(w, "</code>{}</h4>", src)?;
4124-
} else {
4125-
write!(w, "{}</span></td></tr></tbody></table></h4>", src)?;
4088+
write!(w, "</code>")?;
4089+
render_stability_since_raw(w, item.stable_since(), outer_version)?;
4090+
if let Some(l) = (Item { cx, item }).src_href() {
4091+
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
4092+
l, "goto source code")?;
41264093
}
4094+
write!(w, "</h4>")?;
41274095
}
41284096
clean::AssociatedTypeItem(ref bounds, ref default) => {
41294097
let id = cx.derive_id(format!("{}.{}", item_type, name));

src/librustdoc/html/static/main.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -2409,8 +2409,17 @@ if (!DOMTokenList.prototype.remove) {
24092409
e.remove();
24102410
});
24112411
onEachLazy(main.childNodes, function(e) {
2412+
// Unhide the actual content once loading is complete. Headers get
2413+
// flex treatment for their horizontal layout, divs get block treatment
2414+
// for vertical layout (column-oriented flex layout for divs caused
2415+
// errors in mobile browsers).
24122416
if (e.tagName === "H2" || e.tagName === "H3") {
2413-
e.nextElementSibling.style.display = "block";
2417+
let nextTagName = e.nextElementSibling.tagName;
2418+
if (nextTagName == "H2" || nextTagName == "H3") {
2419+
e.nextElementSibling.style.display = "flex";
2420+
} else {
2421+
e.nextElementSibling.style.display = "block";
2422+
}
24142423
}
24152424
});
24162425
}

src/librustdoc/html/static/rustdoc.css

+39-14
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.t
8989
border-bottom: 1px solid;
9090
}
9191
h3.impl, h3.method, h4.method, h3.type, h4.type, h4.associatedconstant {
92+
flex-basis: 100%;
9293
font-weight: 600;
93-
margin-top: 10px;
94+
margin-top: 16px;
9495
margin-bottom: 10px;
9596
position: relative;
9697
}
@@ -356,7 +357,8 @@ nav.sub {
356357
#main > .docblock h3, #main > .docblock h4, #main > .docblock h5 { font-size: 1em; }
357358

358359
#main > h2 + div, #main > h2 + h3, #main > h3 + div {
359-
display: none;
360+
display: none; /* Changed to flex or block via js once the page is loaded */
361+
flex-wrap: wrap;
360362
}
361363

362364
.docblock h1 { font-size: 1em; }
@@ -390,7 +392,7 @@ h4 > code, h3 > code, .invisible > code {
390392
}
391393

392394
.in-band, code {
393-
z-index: 5;
395+
z-index: -5;
394396
}
395397

396398
.invisible {
@@ -534,6 +536,10 @@ h4 > code, h3 > code, .invisible > code {
534536
margin-top: -8px;
535537
}
536538

539+
.impl-items {
540+
flex-basis: 100%;
541+
}
542+
537543
#main > .stability {
538544
margin-top: 0;
539545
}
@@ -784,6 +790,33 @@ body.blur > :not(#help) {
784790
top: 0;
785791
}
786792

793+
.impl-items .since, .impl .since {
794+
flex-grow: 0;
795+
padding-left: 12px;
796+
padding-right: 2px;
797+
position: initial;
798+
}
799+
800+
.impl-items .srclink, .impl .srclink {
801+
flex-grow: 0;
802+
/* Override header settings otherwise it's too bold */
803+
font-size: 17px;
804+
font-weight: normal;
805+
}
806+
807+
.impl-items code, .impl code {
808+
flex-grow: 1;
809+
}
810+
811+
.impl-items h4, h4.impl, h3.impl {
812+
display: flex;
813+
flex-basis: 100%;
814+
font-size: 16px;
815+
margin-bottom: 12px;
816+
/* Push the src link out to the right edge consistently */
817+
justify-content: space-between;
818+
}
819+
787820
.variants_table {
788821
width: 100%;
789822
}
@@ -871,15 +904,6 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
871904
margin-left: 20px;
872905
}
873906

874-
.ghost {
875-
display: none;
876-
}
877-
878-
.ghost + .since {
879-
position: initial;
880-
display: table-cell;
881-
}
882-
883907
.since + .srclink {
884908
display: table-cell;
885909
padding-left: 10px;
@@ -1119,7 +1143,7 @@ span.since {
11191143
margin-left: 5px;
11201144
top: -5px;
11211145
left: 105%;
1122-
z-index: 1;
1146+
z-index: 10;
11231147
}
11241148

11251149
.tooltip:hover .tooltiptext {
@@ -1361,8 +1385,9 @@ h3.important {
13611385
margin-top: 16px;
13621386
}
13631387

1364-
.content > .methods > div.important-traits {
1388+
.content > .methods > .method > div.important-traits {
13651389
position: absolute;
1390+
font-weight: 400;
13661391
left: -42px;
13671392
margin-top: 2px;
13681393
}

src/test/rustdoc/assoc-consts-version.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
pub struct SomeStruct;
1111

1212
impl SomeStruct {
13-
// @has 'foo/struct.SomeStruct.html' '//*[@id="SOME_CONST.v"]//div[@class="since"]' '1.1.2'
13+
// @has 'foo/struct.SomeStruct.html' '//*[@id="associatedconstant.SOME_CONST"]//div[@class="since"]' '1.1.2'
1414
#[stable(since="1.1.2", feature="rust2")]
1515
pub const SOME_CONST: usize = 0;
1616
}

src/test/rustdoc/const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pub struct Foo;
44

55
impl Foo {
6-
// @has const/struct.Foo.html '//*[@id="new.v"]//code' 'const unsafe fn new'
6+
// @has const/struct.Foo.html '//code[@id="new.v"]' 'const unsafe fn new'
77
pub const unsafe fn new() -> Foo {
88
Foo
99
}

src/test/rustdoc/issue-25001.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ pub trait Bar {
99

1010
impl Foo<u8> {
1111
// @has - '//*[@id="method.pass"]//code' 'fn pass()'
12-
// @has - '//*[@id="pass.v"]//code' 'fn pass()'
12+
// @has - '//code[@id="pass.v"]' 'fn pass()'
1313
pub fn pass() {}
1414
}
1515
impl Foo<u16> {
1616
// @has - '//*[@id="method.pass-1"]//code' 'fn pass() -> usize'
17-
// @has - '//*[@id="pass.v-1"]//code' 'fn pass() -> usize'
17+
// @has - '//code[@id="pass.v-1"]' 'fn pass() -> usize'
1818
pub fn pass() -> usize { 42 }
1919
}
2020
impl Foo<u32> {
2121
// @has - '//*[@id="method.pass-2"]//code' 'fn pass() -> isize'
22-
// @has - '//*[@id="pass.v-2"]//code' 'fn pass() -> isize'
22+
// @has - '//code[@id="pass.v-2"]' 'fn pass() -> isize'
2323
pub fn pass() -> isize { 42 }
2424
}
2525

src/test/rustdoc/issue-51236.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub mod traits {
77
}
88

99
// @has issue_51236/struct.Owned.html
10-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<T> Send for \
10+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<T> Send for \
1111
// Owned<T> where <T as Owned<'static>>::Reader: Send"
1212
pub struct Owned<T> where T: for<'a> ::traits::Owned<'a> {
1313
marker: PhantomData<<T as ::traits::Owned<'static>>::Reader>,

src/test/rustdoc/issue-54705.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ pub trait ScopeHandle<'scope> {}
33

44

55
// @has issue_54705/struct.ScopeFutureContents.html
6-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<'scope, S> \
6+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'scope, S> \
77
// Send for ScopeFutureContents<'scope, S> where S: Sync"
88
//
9-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<'scope, S> \
9+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'scope, S> \
1010
// Sync for ScopeFutureContents<'scope, S> where S: Sync"
1111
pub struct ScopeFutureContents<'scope, S>
1212
where S: ScopeHandle<'scope>,

src/test/rustdoc/issue-55321.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#![feature(optin_builtin_traits)]
22

33
// @has issue_55321/struct.A.html
4-
// @has - '//*[@id="implementations-list"]/*[@class="impl"]//*/code' "impl !Send for A"
5-
// @has - '//*[@id="implementations-list"]/*[@class="impl"]//*/code' "impl !Sync for A"
4+
// @has - '//*[@id="implementations-list"]/*[@class="impl"]//code' "impl !Send for A"
5+
// @has - '//*[@id="implementations-list"]/*[@class="impl"]//code' "impl !Sync for A"
66
pub struct A();
77

88
impl !Send for A {}
99
impl !Sync for A {}
1010

1111
// @has issue_55321/struct.B.html
12-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<T> !Send for \
12+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<T> !Send for \
1313
// B<T>"
14-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<T> !Sync for \
14+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<T> !Sync for \
1515
// B<T>"
1616
pub struct B<T: ?Sized>(A, Box<T>);

src/test/rustdoc/issue-56822.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<'a, T> MyTrait for Inner<'a, T> {
1717
}
1818

1919
// @has issue_56822/struct.Parser.html
20-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<'a> Send for \
20+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'a> Send for \
2121
// Parser<'a>"
2222
pub struct Parser<'a> {
2323
field: <Wrapper<Inner<'a, u8>> as MyTrait>::Output

src/test/rustdoc/synthetic_auto/complex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod foo {
2020
}
2121

2222
// @has complex/struct.NotOuter.html
23-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<'a, T, K: \
23+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'a, T, K: \
2424
// ?Sized> Send for NotOuter<'a, T, K> where K: for<'b> Fn((&'b bool, &'a u8)) \
2525
// -> &'b i8, T: MyTrait<'a>, <T as MyTrait<'a>>::MyItem: Copy, 'a: 'static"
2626

src/test/rustdoc/synthetic_auto/lifetimes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ where
99
{}
1010

1111
// @has lifetimes/struct.Foo.html
12-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<'c, K> Send \
12+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'c, K> Send \
1313
// for Foo<'c, K> where K: for<'b> Fn(&'b bool) -> &'c u8, 'c: 'static"
1414
//
15-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<'c, K> Sync \
15+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'c, K> Sync \
1616
// for Foo<'c, K> where K: Sync"
1717
pub struct Foo<'c, K: 'c> {
1818
inner_field: Inner<'c, K>,

src/test/rustdoc/synthetic_auto/manual.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// @has manual/struct.Foo.html
2-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' 'impl<T> Sync for \
2+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' 'impl<T> Sync for \
33
// Foo<T> where T: Sync'
44
//
5-
// @has - '//*[@id="implementations-list"]/*[@class="impl"]//*/code' \
5+
// @has - '//*[@id="implementations-list"]/*[@class="impl"]//code' \
66
// 'impl<T> Send for Foo<T>'
77
//
88
// @count - '//*[@id="implementations-list"]/*[@class="impl"]' 1

src/test/rustdoc/synthetic_auto/negative.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ pub struct Inner<T: Copy> {
33
}
44

55
// @has negative/struct.Outer.html
6-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<T> !Send for \
6+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<T> !Send for \
77
// Outer<T>"
88
//
9-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<T> \
9+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<T> \
1010
// !Sync for Outer<T>"
1111
pub struct Outer<T: Copy> {
1212
inner_field: Inner<T>,

0 commit comments

Comments
 (0)