From 8ccee61d38b94f868da9ae11ad5efd69d7a04072 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 10 Jul 2021 14:58:36 +0200 Subject: [PATCH] Fix display for external trait implementors --- src/librustdoc/html/static/js/main.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 98128878999..38ddbb3ad74 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -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 = "" + - "" + - "
" + code.outerHTML + "
"; + display.appendChild(anchor); + display.appendChild(code); list.appendChild(display); + currentNbImpls += 1; } } };