diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 970c2f2d45d..aa8fd7162ee 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -370,8 +370,12 @@ function preLoadCss(cssUrl) { item => { const numbered = /([^-]+)-([0-9]+)/.exec(item.id); if (item.id === assocId || (numbered && numbered[1] === assocId)) { - expandSection(item.id); - window.location = "#" + item.id; + openParentDetails(item); + item.scrollIntoView(); + // Let the section expand itself before trying to highlight + setTimeout(() => { + window.location.replace("#" + item.id); + }, 0); } } ); diff --git a/tests/rustdoc-gui/search-result-impl-disambiguation.goml b/tests/rustdoc-gui/search-result-impl-disambiguation.goml index 98a2cd95773..1596a3c4c6e 100644 --- a/tests/rustdoc-gui/search-result-impl-disambiguation.goml +++ b/tests/rustdoc-gui/search-result-impl-disambiguation.goml @@ -20,6 +20,7 @@ wait-for: "#impl-ZyxwvutMethodDisambiguation" assert-document-property: ({ "URL": "struct.ZyxwvutMethodDisambiguation.html#method.method_impl_disambiguation" }, ENDS_WITH) +assert: "section:target" goto: "file://" + |DOC_PATH| + "/test_docs/index.html" @@ -39,3 +40,4 @@ wait-for: "#impl-ZyxwvutMethodDisambiguation" assert-document-property: ({ "URL": "struct.ZyxwvutMethodDisambiguation.html#method.method_impl_disambiguation-1" }, ENDS_WITH) +assert: "section:target"