Rollup merge of #87035 - GuillaumeGomez:fix-implementors-display, r=notriddle

Fix implementors display

Part of https://github.com/rust-lang/rust/issues/86632.

This PR does a few things:
 * It fixes of the JS rendered implementors.
 * It generates anchors for JS rendered implementors to make it coherent with the others.
 * It adds a test to ensure that we won't have the same issue again.
 * It changes the way we render the rustdoc-gui crates to simplify it a bit and also to allow to have dependencies without going through compiletest.

Before:

![Screenshot from 2021-07-10 13-30-13](https://user-images.githubusercontent.com/3050060/125174172-b4048700-e1c3-11eb-8f0e-c46081371d4f.png)

After:

![Screenshot from 2021-07-10 21-11-15](https://user-images.githubusercontent.com/3050060/125174173-b49d1d80-e1c3-11eb-8740-1dbbff70c2eb.png)

I plan to add the `[src]` links in another PR because this one is already big enough.

cc `@Mark-Simulacrum` (for the bootstrap changes)

r? `@Nemo157`
This commit is contained in:
Yuki Okushi 2021-07-13 08:54:33 +09:00 committed by GitHub
commit fab45bf485
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 109 additions and 18 deletions

View file

@ -683,6 +683,9 @@ function hideThemeButtonState() {
});
}
var currentNbImpls = implementors.getElementsByClassName("impl").length;
var traitName = document.querySelector("h1.fqn > .in-band > .trait").textContent;
var baseIdName = "impl-" + traitName + "-";
var libs = Object.getOwnPropertyNames(imp);
for (var i = 0, llength = libs.length; i < llength; ++i) {
if (libs[i] === window.currentCrate) { continue; }
@ -705,6 +708,7 @@ function hideThemeButtonState() {
var code = document.createElement("code");
code.innerHTML = struct.text;
addClass(code, "in-band");
onEachLazy(code.getElementsByTagName("a"), function(elem) {
var href = elem.getAttribute("href");
@ -714,12 +718,18 @@ function hideThemeButtonState() {
}
});
var display = document.createElement("h3");
var currentId = baseIdName + currentNbImpls;
var anchor = document.createElement("a");
anchor.href = "#" + currentId;
addClass(anchor, "anchor");
var display = document.createElement("div");
display.id = currentId;
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>";
display.appendChild(anchor);
display.appendChild(code);
list.appendChild(display);
currentNbImpls += 1;
}
}
};