Skip to content

Commit a2ba9ef

Browse files
Only list crates on the crate page
1 parent e081cd4 commit a2ba9ef

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/librustdoc/html/render/context.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,15 @@ impl<'tcx> Context<'tcx> {
200200
)
201201
};
202202
let keywords = make_item_keywords(it);
203+
let name;
204+
let tyname_s = if it.is_crate() {
205+
name = format!("{} crate", tyname);
206+
name.as_str()
207+
} else {
208+
tyname.as_str()
209+
};
203210
let page = layout::Page {
204-
css_class: tyname.as_str(),
211+
css_class: tyname_s,
205212
root_path: &self.root_path(),
206213
static_root_path: self.shared.static_root_path.as_deref(),
207214
title: &title,

src/librustdoc/html/static/main.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,12 @@ function hideThemeButtonState() {
565565
window.initSidebarItems = function(items) {
566566
var sidebar = document.getElementsByClassName("sidebar-elems")[0];
567567
var current = window.sidebarCurrent;
568-
var isModule = hasClass(document.body, "mod");
569568

570569
function addSidebarCrates(crates) {
570+
if (!hasClass(document.body, "crate")) {
571+
// We only want to list crates on the crate page.
572+
return;
573+
}
571574
// Draw a convenient sidebar of known crates if we have a listing
572575
var div = document.createElement("div");
573576
div.className = "block crate";
@@ -634,6 +637,7 @@ function hideThemeButtonState() {
634637
}
635638

636639
if (sidebar) {
640+
var isModule = hasClass(document.body, "mod");
637641
if (!isModule) {
638642
block("primitive", "Primitive Types");
639643
block("mod", "Modules");

src/test/rustdoc-gui/sidebar.goml

+7-8
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ click: "#structs + table td > a"
1717

1818
// PAGE: struct.Foo.html
1919
assert: (".sidebar .location", 2)
20-
// We check that we have the crates list and that the "current" on is still "test_docs".
21-
assert: (".sidebar-elems > .crate > ul > li > a.current", "test_docs")
22-
// We now move to the other crate to check if its submodules have the correct sidebar elements too.
23-
click: ".sidebar-elems > .crate > ul > li:first-child > a"
20+
// We check that there is no crate listed outside of the top level.
21+
assert-false: ".sidebar-elems > .crate"
2422

2523
// PAGE: lib2/index.html
24+
goto: file://|DOC_PATH|/lib2/index.html
2625
assert: (".sidebar > .location", "Crate lib2")
2726
// We check that we have the crates list and that the "current" on is now "lib2".
2827
assert: (".sidebar-elems > .crate > ul > li > a.current", "lib2")
@@ -36,12 +35,12 @@ click: "#functions + table td > a"
3635
// In items containing no items (like functions or constants) and in modules, we have one
3736
// "location" elements.
3837
assert: (".sidebar .location", 1)
39-
// We check that we still have the crates list and that the "current" on is still "lib2".
40-
assert: (".sidebar-elems > .crate > ul > li > a.current", "lib2")
38+
// We check that we don't have the crate list.
39+
assert-false: ".sidebar-elems > .crate"
4140
goto: ./module/sub_module/sub_sub_module/index.html
4241

4342
assert: (".sidebar > .location", "Module sub_sub_module")
44-
assert: (".sidebar-elems > .crate > ul > li:nth-child(2) > a", "test_docs")
45-
assert: (".sidebar-elems > .crate > ul > li:nth-child(2) > a", "href", "../../../../test_docs/index.html")
43+
// We check that we don't have the crate list.
44+
assert-false: ".sidebar-elems > .crate"
4645
assert: (".sidebar-elems > .items > ul > li:nth-child(1)", "Functions")
4746
assert: ("#functions + table td > a", "foo")

0 commit comments

Comments
 (0)