Skip to content

Commit e76a5eb

Browse files
Make implementors list visible only when filled
1 parent bc014e0 commit e76a5eb

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

src/librustdoc/html/static/css/noscript.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ nav.sub {
2929
display: none;
3030
}
3131

32+
#synthetic-implementors-list, #implementors-list {
33+
display: block;
34+
}
35+
3236
/* Begin: styles for themes
3337
Keep the default light and dark themes synchronized with the ones
3438
in rustdoc.css */

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,12 @@ div.where {
11251125
margin-left: calc(var(--docblock-indent) + var(--impl-items-indent));
11261126
}
11271127

1128+
#synthetic-implementors-list, #implementors-list {
1129+
/* To prevent layout shift when loading the page with extra implementors being loaded
1130+
from JS, we hide the list until it's complete. */
1131+
display: none;
1132+
}
1133+
11281134
.item-info code {
11291135
font-size: 0.875rem;
11301136
}

src/librustdoc/html/static/js/main.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,21 +687,21 @@ function preLoadCss(cssUrl) {
687687
return [elem, elem ? elem.querySelector(".negative-marker") : null];
688688
}
689689
const implementors = implementorsElems("implementors-list");
690-
const synthetic_implementors = implementorsElems("synthetic-implementors-list");
690+
const syntheticImplementors = implementorsElems("synthetic-implementors-list");
691691
const inlined_types = new Set();
692692

693693
const TEXT_IDX = 0;
694694
const IS_NEG_IDX = 1;
695695
const SYNTHETIC_IDX = 2;
696696
const TYPES_IDX = 3;
697697

698-
if (synthetic_implementors[0]) {
698+
if (syntheticImplementors[0]) {
699699
// This `inlined_types` variable is used to avoid having the same implementation
700700
// showing up twice. For example "String" in the "Sync" doc page.
701701
//
702702
// By the way, this is only used by and useful for traits implemented automatically
703703
// (like "Send" and "Sync").
704-
onEachLazy(synthetic_implementors[0].getElementsByClassName("impl"), el => {
704+
onEachLazy(syntheticImplementors[0].getElementsByClassName("impl"), el => {
705705
const aliases = el.getAttribute("data-aliases");
706706
if (!aliases) {
707707
return;
@@ -736,7 +736,7 @@ function preLoadCss(cssUrl) {
736736

737737
struct_loop:
738738
for (const struct of structs) {
739-
const list = struct[SYNTHETIC_IDX] ? synthetic_implementors : implementors;
739+
const list = struct[SYNTHETIC_IDX] ? syntheticImplementors : implementors;
740740

741741
// The types list is only used for synthetic impls.
742742
// If this changes, `main.js` and `write_shared.rs` both need changed.
@@ -784,6 +784,12 @@ function preLoadCss(cssUrl) {
784784
currentNbImpls += 1;
785785
}
786786
}
787+
if (implementors[0]) {
788+
implementors[0].style.display = "block";
789+
}
790+
if (syntheticImplementors[0]) {
791+
syntheticImplementors[0].style.display = "block";
792+
}
787793
};
788794
if (window.pending_implementors) {
789795
window.register_implementors(window.pending_implementors);

tests/rustdoc-gui/implementors.goml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// The goal of this test is to check that the external trait implementors, generated with JS,
22
// have the same display than the "local" ones.
33
go-to: "file://" + |DOC_PATH| + "/implementors/trait.Whatever.html"
4-
assert: "#implementors-list"
4+
wait-for-css: ("#implementors-list", {"display": "block"})
55
// There are supposed to be four implementors listed.
66
assert-count: ("#implementors-list .impl", 4)
77
// There are supposed to be two non-negative implementors.
@@ -66,3 +66,8 @@ assert-count: ("#implementors-list .impl", 1)
6666
go-to: "file://" + |DOC_PATH| + "/http/trait.HttpTrait.html"
6767
assert-count: ("#implementors-list .impl", 1)
6868
assert-attribute: ("#implementors-list .impl a.trait", {"href": "../http/trait.HttpTrait.html"})
69+
70+
// Now we check that if JS is disabled, the implementors list will be visible.
71+
javascript: false
72+
reload:
73+
assert-css: ("#implementors-list", {"display": "block"})

0 commit comments

Comments
 (0)