Skip to content

Commit 34bd2b8

Browse files
committed
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 std::iter::Iterator by 30%.
1 parent f8caa32 commit 34bd2b8

19 files changed

+95
-93
lines changed

src/librustdoc/html/render.rs

+19-51
Original file line numberDiff line numberDiff line change
@@ -3051,7 +3051,7 @@ fn item_trait(
30513051
let item_type = m.type_();
30523052
let id = cx.derive_id(format!("{}.{}", item_type, name));
30533053
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
3054-
write!(w, "{extra}<h3 id='{id}' class='method'><code id='{ns_id}'>",
3054+
write!(w, "<h3 id='{id}' class='method'>{extra}<code id='{ns_id}'>",
30553055
extra = render_spotlight_traits(m)?,
30563056
id = id,
30573057
ns_id = ns_id)?;
@@ -3436,7 +3436,7 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
34363436
let id = format!("{}.{}", ItemType::StructField, name);
34373437
write!(w, "<span id=\"{id}\" class=\"{shortty} small-section-header\">\
34383438
<a href=\"#{id}\" class=\"anchor field\"></a>\
3439-
<span class='invisible'><code>{name}: {ty}</code></span>\
3439+
<code>{name}: {ty}</code>\
34403440
</span>",
34413441
id = id,
34423442
name = name,
@@ -3991,8 +3991,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
39913991
None => "impl".to_string(),
39923992
});
39933993
if let Some(use_absolute) = use_absolute {
3994-
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
3995-
<tbody><tr><td><code>", id)?;
3994+
write!(w, "<h3 id='{}' class='impl'><code class='in-band'>", id)?;
39963995
fmt_impl_for_trait_page(&i.inner_impl(), w, use_absolute)?;
39973996
if show_def_docs {
39983997
for it in &i.inner_impl().items {
@@ -4006,22 +4005,18 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
40064005
}
40074006
write!(w, "</code>")?;
40084007
} else {
4009-
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
4010-
<tbody><tr><td><code>{}</code>",
4011-
id, i.inner_impl())?;
4008+
write!(w, "<h3 id='{}' class='impl'><code class='in-band'>{}</code>",
4009+
id, i.inner_impl()
4010+
)?;
40124011
}
40134012
write!(w, "<a href='#{}' class='anchor'></a>", id)?;
4014-
write!(w, "</td><td><span class='out-of-band'>")?;
40154013
let since = i.impl_item.stability.as_ref().map(|s| &s.since[..]);
4014+
render_stability_since_raw(w, since, outer_version)?;
40164015
if let Some(l) = (Item { item: &i.impl_item, cx: cx }).src_href() {
4017-
write!(w, "<div class='ghost'></div>")?;
4018-
render_stability_since_raw(w, since, outer_version)?;
40194016
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
40204017
l, "goto source code")?;
4021-
} else {
4022-
render_stability_since_raw(w, since, outer_version)?;
40234018
}
4024-
write!(w, "</span></td></tr></tbody></table></span></h3>")?;
4019+
write!(w, "</h3>")?;
40254020
if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) {
40264021
let mut ids = cx.id_map.borrow_mut();
40274022
write!(w, "<div class='docblock'>{}</div>",
@@ -4057,20 +4052,15 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
40574052
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
40584053
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class)?;
40594054
write!(w, "{}", spotlight_decl(decl)?)?;
4060-
write!(w, "<table id='{}' class='table-display'><tbody><tr><td><code>", ns_id)?;
4055+
write!(w, "<code id='{}'>", ns_id)?;
40614056
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl)?;
40624057
write!(w, "</code>")?;
4058+
render_stability_since_raw(w, item.stable_since(), outer_version)?;
40634059
if let Some(l) = (Item { cx, item }).src_href() {
4064-
write!(w, "</td><td><span class='out-of-band'>")?;
4065-
write!(w, "<div class='ghost'></div>")?;
4066-
render_stability_since_raw(w, item.stable_since(), outer_version)?;
4067-
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a></span>",
4060+
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
40684061
l, "goto source code")?;
4069-
} else {
4070-
write!(w, "</td><td>")?;
4071-
render_stability_since_raw(w, item.stable_since(), outer_version)?;
40724062
}
4073-
write!(w, "</td></tr></tbody></table></h4>")?;
4063+
write!(w, "</h4>")?;
40744064
}
40754065
}
40764066
clean::TypedefItem(ref tydef, _) => {
@@ -4082,40 +4072,18 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
40824072
write!(w, "</code></h4>")?;
40834073
}
40844074
clean::AssociatedConstItem(ref ty, ref default) => {
4085-
let mut version = String::new();
4086-
4087-
render_stability_since_raw(&mut version, item.stable_since(), outer_version)?;
4088-
40894075
let id = cx.derive_id(format!("{}.{}", item_type, name));
40904076
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
40914077
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class)?;
4092-
if !version.is_empty() {
4093-
write!(w, "<table id='{}' class='table-display'><tbody><tr><td><code>", ns_id)?;
4094-
} else {
4095-
write!(w, "<code id='{}'>", ns_id)?;
4096-
}
4078+
write!(w, "<code id='{}'>", ns_id)?;
40974079
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id))?;
4098-
if !version.is_empty() {
4099-
write!(w, "</code>")?;
4100-
}
4101-
let src = if let Some(l) = (Item { cx, item }).src_href() {
4102-
if !version.is_empty() {
4103-
write!(w, "</td><td><span class='out-of-band'>")?;
4104-
write!(w, "<div class='ghost'></div>{}", version)?;
4105-
}
4106-
format!("<a class='srclink' href='{}' title='{}'>[src]</a>",
4107-
l, "goto source code")
4108-
} else {
4109-
if !version.is_empty() {
4110-
write!(w, "</td><td>{}", version)?;
4111-
}
4112-
String::new()
4113-
};
4114-
if version.is_empty() {
4115-
write!(w, "</code>{}</h4>", src)?;
4116-
} else {
4117-
write!(w, "{}</span></td></tr></tbody></table></h4>", src)?;
4080+
write!(w, "</code>")?;
4081+
render_stability_since_raw(w, item.stable_since(), outer_version)?;
4082+
if let Some(l) = (Item { cx, item }).src_href() {
4083+
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
4084+
l, "goto source code")?;
41184085
}
4086+
write!(w, "</h4>")?;
41194087
}
41204088
clean::AssociatedTypeItem(ref bounds, ref default) => {
41214089
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
@@ -90,8 +90,9 @@ h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.t
9090
border-bottom: 1px solid;
9191
}
9292
h3.impl, h3.method, h4.method, h3.type, h4.type, h4.associatedconstant {
93+
flex-basis: 100%;
9394
font-weight: 600;
94-
margin-top: 10px;
95+
margin-top: 16px;
9596
margin-bottom: 10px;
9697
position: relative;
9798
}
@@ -357,7 +358,8 @@ nav.sub {
357358
#main > .docblock h3, #main > .docblock h4, #main > .docblock h5 { font-size: 1em; }
358359

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

363365
.docblock h1 { font-size: 1em; }
@@ -391,7 +393,7 @@ h4 > code, h3 > code, .invisible > code {
391393
}
392394

393395
.in-band, code {
394-
z-index: 5;
396+
z-index: -5;
395397
}
396398

397399
.invisible {
@@ -535,6 +537,10 @@ h4 > code, h3 > code, .invisible > code {
535537
margin-top: -8px;
536538
}
537539

540+
.impl-items {
541+
flex-basis: 100%;
542+
}
543+
538544
#main > .stability {
539545
margin-top: 0;
540546
}
@@ -781,6 +787,33 @@ body.blur > :not(#help) {
781787
top: 0;
782788
}
783789

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

871-
.ghost {
872-
display: none;
873-
}
874-
875-
.ghost + .since {
876-
position: initial;
877-
display: table-cell;
878-
}
879-
880904
.since + .srclink {
881905
display: table-cell;
882906
padding-left: 10px;
@@ -1116,7 +1140,7 @@ span.since {
11161140
margin-left: 5px;
11171141
top: -5px;
11181142
left: 105%;
1119-
z-index: 1;
1143+
z-index: 10;
11201144
}
11211145

11221146
.tooltip:hover .tooltiptext {
@@ -1358,8 +1382,9 @@ h3.important {
13581382
margin-top: 16px;
13591383
}
13601384

1361-
.content > .methods > div.important-traits {
1385+
.content > .methods > .method > div.important-traits {
13621386
position: absolute;
1387+
font-weight: 400;
13631388
left: -42px;
13641389
margin-top: 2px;
13651390
}

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
@@ -27,7 +27,7 @@ impl<'a, T> MyTrait for Inner<'a, T> {
2727
}
2828

2929
// @has issue_56822/struct.Parser.html
30-
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<'a> Send for \
30+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'a> Send for \
3131
// Parser<'a>"
3232
pub struct Parser<'a> {
3333
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)