Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate list instead of div items in sidebar #93780

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 104 additions & 121 deletions src/librustdoc/html/render/mod.rs

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,6 @@ h2.location a {
overflow: hidden;
}

.sidebar-links a {
white-space: nowrap;
}

.sidebar h2 {
border-bottom: none;
font-weight: 500;
Expand All @@ -504,11 +500,14 @@ h2.location a {
margin: 0;
}

.sidebar-links,
.block {
.sidebar-elems .block {
margin-bottom: 2em;
}

.sidebar-elems .block li a {
white-space: nowrap;
}

.mobile-topbar {
display: none;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc-gui/hash-item-expansion.goml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ assert-attribute: ("#blanket-implementations-list > details:nth-child(2)", {"ope
// We first check that the impl block is open by default.
assert-attribute: ("#implementations + details", {"open": ""})
// To ensure that we will click on the currently hidden method.
assert-text: (".sidebar-links > a", "must_use")
click: ".sidebar-links > a"
assert-text: (".sidebar-elems section .block li > a", "must_use")
click: ".sidebar-elems section .block li > a"
// We check that the impl block was opened as expected so that we can see the method.
assert-attribute: ("#implementations + details", {"open": ""})
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/sidebar-mobile.goml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ assert-property: (".mobile-topbar", {"clientHeight": "45"})
// Check that clicking an element from the sidebar scrolls to the right place
// so the target is not obscured by the topbar.
click: ".sidebar-menu-toggle"
click: ".sidebar-links a"
click: ".sidebar-elems section .block li > a"
assert-position: ("#method\.must_use", {"y": 45})

// Check that the bottom-most item on the sidebar menu can be scrolled fully into view.
Expand Down
34 changes: 17 additions & 17 deletions src/test/rustdoc-gui/sidebar.goml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ assert-css: ("#all-types", {"color": "rgb(53, 109, 164)"})
// We check that we have the crates list and that the "current" on is "test_docs".
assert-text: (".sidebar-elems .crate > ul > li > a.current", "test_docs")
// And we're also supposed to have the list of items in the current module.
assert-text: (".sidebar-elems .items > ul > li:nth-child(1)", "Modules")
assert-text: (".sidebar-elems .items > ul > li:nth-child(2)", "Macros")
assert-text: (".sidebar-elems .items > ul > li:nth-child(3)", "Structs")
assert-text: (".sidebar-elems .items > ul > li:nth-child(4)", "Enums")
assert-text: (".sidebar-elems .items > ul > li:nth-child(5)", "Traits")
assert-text: (".sidebar-elems .items > ul > li:nth-child(6)", "Functions")
assert-text: (".sidebar-elems .items > ul > li:nth-child(7)", "Type Definitions")
assert-text: (".sidebar-elems .items > ul > li:nth-child(8)", "Unions")
assert-text: (".sidebar-elems .items > ul > li:nth-child(9)", "Keywords")
assert-text: (".sidebar-elems section ul > li:nth-child(1)", "Modules")
assert-text: (".sidebar-elems section ul > li:nth-child(2)", "Macros")
assert-text: (".sidebar-elems section ul > li:nth-child(3)", "Structs")
assert-text: (".sidebar-elems section ul > li:nth-child(4)", "Enums")
assert-text: (".sidebar-elems section ul > li:nth-child(5)", "Traits")
assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Functions")
assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Type Definitions")
assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Unions")
assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Keywords")
assert-text: ("#structs + .item-table .item-left > a", "Foo")
click: "#structs + .item-table .item-left > a"

Expand All @@ -30,7 +30,7 @@ assert-count: (".sidebar .location", 2)
// We check that there is no crate listed outside of the top level.
assert-false: ".sidebar-elems > .crate"

click: ".sidebar-links a"
click: ".sidebar-elems section .block li > a"
assert-property-false: ("html", {"scrollTop": "0"})

click: ".sidebar h2.location a"
Expand All @@ -47,11 +47,11 @@ assert-text: (".sidebar > .location", "Crate lib2")
// We check that we have the crates list and that the "current" on is now "lib2".
assert-text: (".sidebar-elems .crate > ul > li > a.current", "lib2")
// We now go to the "foobar" function page.
assert-text: (".sidebar-elems > .items > ul > li:nth-child(1)", "Modules")
assert-text: (".sidebar-elems > .items > ul > li:nth-child(2)", "Structs")
assert-text: (".sidebar-elems > .items > ul > li:nth-child(3)", "Traits")
assert-text: (".sidebar-elems > .items > ul > li:nth-child(4)", "Functions")
assert-text: (".sidebar-elems > .items > ul > li:nth-child(5)", "Type Definitions")
assert-text: (".sidebar-elems > section .block ul > li:nth-child(1)", "Modules")
assert-text: (".sidebar-elems > section .block ul > li:nth-child(2)", "Structs")
assert-text: (".sidebar-elems > section .block ul > li:nth-child(3)", "Traits")
assert-text: (".sidebar-elems > section .block ul > li:nth-child(4)", "Functions")
assert-text: (".sidebar-elems > section .block ul > li:nth-child(5)", "Type Definitions")
assert-text: ("#functions + .item-table .item-left > a", "foobar")
click: "#functions + .item-table .item-left > a"

Expand All @@ -72,12 +72,12 @@ goto: ./sub_module/sub_sub_module/index.html
assert-text: (".sidebar > .location", "Module sub_sub_module")
// We check that we don't have the crate list.
assert-false: ".sidebar-elems .crate"
assert-text: (".sidebar-elems .items > ul > li:nth-child(1)", "Functions")
assert-text: (".sidebar-elems > section ul > li:nth-child(1)", "Functions")
assert-text: ("#functions + .item-table .item-left > a", "foo")

// Links to trait implementations in the sidebar should not wrap even if they are long.
goto: file://|DOC_PATH|/lib2/struct.HasALongTraitWithParams.html
assert-property: (".sidebar-links a", {"offsetHeight": 29})
assert-property: (".sidebar-elems section .block li > a", {"offsetHeight": 29})

// Test that clicking on of the "In <module>" headings in the sidebar links to the
// appropriate anchor in index.html.
Expand Down
12 changes: 6 additions & 6 deletions src/test/rustdoc-gui/trait-sidebar-item-order.goml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Checks that the elements in the sidebar are alphabetically sorted.
goto: file://|DOC_PATH|/test_docs/trait.AnotherOne.html
assert-text: (".sidebar-links a:nth-of-type(1)", "another")
assert-text: (".sidebar-links a:nth-of-type(2)", "func1")
assert-text: (".sidebar-links a:nth-of-type(3)", "func2")
assert-text: (".sidebar-links a:nth-of-type(4)", "func3")
assert-text: (".sidebar-links a:nth-of-type(5)", "hello")
assert-text: (".sidebar-links a:nth-of-type(6)", "why_not")
assert-text: (".sidebar-elems section .block li:nth-of-type(1) > a", "another")
assert-text: (".sidebar-elems section .block li:nth-of-type(2) > a", "func1")
assert-text: (".sidebar-elems section .block li:nth-of-type(3) > a", "func2")
assert-text: (".sidebar-elems section .block li:nth-of-type(4) > a", "func3")
assert-text: (".sidebar-elems section .block li:nth-of-type(5) > a", "hello")
assert-text: (".sidebar-elems section .block li:nth-of-type(6) > a", "why_not")
4 changes: 2 additions & 2 deletions src/test/rustdoc/associated-consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Bar;

// @has 'foo/struct.Bar.html'
// @has - '//h3[@class="sidebar-title"]' 'Associated Constants'
// @has - '//div[@class="sidebar-elems"]//div[@class="sidebar-links"]/a' 'FOO'
// @has - '//div[@class="sidebar-elems"]//a' 'FOO'
impl Trait for Bar {
const FOO: u32 = 1;

Expand All @@ -23,7 +23,7 @@ pub enum Foo {

// @has 'foo/enum.Foo.html'
// @has - '//h3[@class="sidebar-title"]' 'Associated Constants'
// @has - '//div[@class="sidebar-elems"]//div[@class="sidebar-links"]/a' 'FOO'
// @has - '//div[@class="sidebar-elems"]//a' 'FOO'
impl Trait for Foo {
const FOO: u32 = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/deref-mut-methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl Foo {
}

// @has foo/struct.Bar.html
// @has - '//div[@class="sidebar-links"]/a[@href="#method.foo"]' 'foo'
// @has - '//*[@class="sidebar-elems"]//*[@class="block"]//a[@href="#method.foo"]' 'foo'
pub struct Bar {
foo: Foo,
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/deref-recursive-pathbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// @has '-' '//*[@id="deref-methods-Path"]' 'Methods from Deref<Target = Path>'
// @has '-' '//*[@class="impl-items"]//*[@id="method.exists"]' 'pub fn exists(&self)'
// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-PathBuf"]' 'Methods from Deref<Target=PathBuf>'
// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.as_path"]' 'as_path'
// @has '-' '//*[@class="sidebar-elems"]//*[@class="block"]//a[@href="#method.as_path"]' 'as_path'
// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-Path"]' 'Methods from Deref<Target=Path>'
// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.exists"]' 'exists'
// @has '-' '//*[@class="sidebar-elems"]//*[@class="block"]//a[@href="#method.exists"]' 'exists'

#![crate_name = "foo"]

Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/deref-recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// @has '-' '//*[@id="deref-methods-Baz"]' 'Methods from Deref<Target = Baz>'
// @has '-' '//*[@class="impl-items"]//*[@id="method.baz"]' 'pub fn baz(&self)'
// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-Bar"]' 'Methods from Deref<Target=Bar>'
// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.bar"]' 'bar'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.bar"]' 'bar'
// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-Baz"]' 'Methods from Deref<Target=Baz>'
// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.baz"]' 'baz'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.baz"]' 'baz'

#![crate_name = "foo"]

Expand Down
8 changes: 4 additions & 4 deletions src/test/rustdoc/deref-typedef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_c"]' 'pub fn foo_c(&self)'
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_j"]' 'pub fn foo_j(&self)'
// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-FooJ"]' 'Methods from Deref<Target=FooJ>'
// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_a"]' 'foo_a'
// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_b"]' 'foo_b'
// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_c"]' 'foo_c'
// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_j"]' 'foo_j'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_a"]' 'foo_a'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_b"]' 'foo_b'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_c"]' 'foo_c'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_j"]' 'foo_j'

pub struct FooA;
pub type FooB = FooA;
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/double-quote-escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pub trait Foo<T> {
pub struct Bar;

// @has foo/struct.Bar.html
// @has - '//*[@class="sidebar-links"]/a[@href="#impl-Foo%3Cunsafe%20extern%20%22C%22%20fn()%3E"]' 'Foo<unsafe extern "C" fn()>'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#impl-Foo%3Cunsafe%20extern%20%22C%22%20fn()%3E"]' 'Foo<unsafe extern "C" fn()>'
impl Foo<unsafe extern "C" fn()> for Bar {}
2 changes: 1 addition & 1 deletion src/test/rustdoc/generic-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Bar;

// @has foo/struct.Foo.html '//*[@id="impl-ToString"]//h3[@class="code-header in-band"]' 'impl<T> ToString for T'
pub struct Foo;
// @has foo/struct.Foo.html '//div[@class="sidebar-links"]/a[@href="#impl-ToString"]' 'ToString'
// @has foo/struct.Foo.html '//*[@class="sidebar-elems"]//section//a[@href="#impl-ToString"]' 'ToString'

impl fmt::Display for Foo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/method-list.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![crate_name = "foo"]

// @has foo/struct.Foo.html
// @has - '//*[@class="sidebar-links"]/a' 'super_long_name'
// @has - '//*[@class="sidebar-links"]/a' 'Disp'
// @has - '//*[@class="sidebar-elems"]//section//a' 'super_long_name'
// @has - '//*[@class="sidebar-elems"]//section//a' 'Disp'
pub struct Foo(usize);

impl Foo {
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/negative-impl-sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ pub struct Foo;

// @has foo/struct.Foo.html
// @has - '//*[@class="sidebar-title"]/a[@href="#trait-implementations"]' 'Trait Implementations'
// @has - '//*[@class="sidebar-links"]/a' '!Sync'
// @has - '//*[@class="sidebar-elems"]//section//a' '!Sync'
impl !Sync for Foo {}
4 changes: 2 additions & 2 deletions src/test/rustdoc/recursive-deref-sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ impl B { pub fn foo_b(&self) {} }
pub struct C {}
impl C { pub fn foo_c(&self) {} }

// @has recursive_deref_sidebar/struct.A.html '//div[@class="sidebar-links"]' 'foo_b'
// @has recursive_deref_sidebar/struct.A.html '//*[@class="sidebar-elems"]//section' 'foo_b'
impl Deref for A {
type Target = B;
fn deref(&self) -> &B { todo!() }
}

// @has recursive_deref_sidebar/struct.A.html '//div[@class="sidebar-links"]' 'foo_c'
// @has recursive_deref_sidebar/struct.A.html '//*[@class="sidebar-elems"]//section' 'foo_c'
impl Deref for B {
type Target = C;
fn deref(&self) -> &C { todo!() }
Expand Down
24 changes: 12 additions & 12 deletions src/test/rustdoc/sidebar-items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

// @has foo/trait.Foo.html
// @has - '//*[@class="sidebar-title"]/a[@href="#required-methods"]' 'Required Methods'
// @has - '//*[@class="sidebar-links"]/a' 'bar'
// @has - '//*[@class="sidebar-elems"]//section//a' 'bar'
// @has - '//*[@class="sidebar-title"]/a[@href="#provided-methods"]' 'Provided Methods'
// @has - '//*[@class="sidebar-links"]/a' 'foo'
// @has - '//*[@class="sidebar-elems"]//section//a' 'foo'
// @has - '//*[@class="sidebar-title"]/a[@href="#associated-const"]' 'Associated Constants'
// @has - '//*[@class="sidebar-links"]/a' 'BAR'
// @has - '//*[@class="sidebar-elems"]//section//a' 'BAR'
// @has - '//*[@class="sidebar-title"]/a[@href="#associated-types"]' 'Associated Types'
// @has - '//*[@class="sidebar-links"]/a' 'Output'
// @has - '//*[@class="sidebar-elems"]//section//a' 'Output'
pub trait Foo {
const BAR: u32 = 0;
type Output: ?Sized;
Expand All @@ -19,9 +19,9 @@ pub trait Foo {

// @has foo/struct.Bar.html
// @has - '//*[@class="sidebar-title"]/a[@href="#fields"]' 'Fields'
// @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f"]' 'f'
// @has - '//*[@class="sidebar-links"]/a[@href="#structfield.u"]' 'u'
// @!has - '//*[@class="sidebar-links"]/a' 'waza'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#structfield.f"]' 'f'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#structfield.u"]' 'u'
// @!has - '//*[@class="sidebar-elems"]//section//a' 'waza'
pub struct Bar {
pub f: u32,
pub u: u32,
Expand All @@ -30,18 +30,18 @@ pub struct Bar {

// @has foo/enum.En.html
// @has - '//*[@class="sidebar-title"]/a[@href="#variants"]' 'Variants'
// @has - '//*[@class="sidebar-links"]/a' 'Foo'
// @has - '//*[@class="sidebar-links"]/a' 'Bar'
// @has - '//*[@class="sidebar-elems"]//section//a' 'Foo'
// @has - '//*[@class="sidebar-elems"]//section//a' 'Bar'
pub enum En {
Foo,
Bar,
}

// @has foo/union.MyUnion.html
// @has - '//*[@class="sidebar-title"]/a[@href="#fields"]' 'Fields'
// @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f1"]' 'f1'
// @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f2"]' 'f2'
// @!has - '//*[@class="sidebar-links"]/a' 'waza'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#structfield.f1"]' 'f1'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#structfield.f2"]' 'f2'
// @!has - '//*[@class="sidebar-elems"]//section//a' 'waza'
pub union MyUnion {
pub f1: u32,
pub f2: f32,
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/sidebar-link-generation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![crate_name = "foo"]

// @has foo/struct.SomeStruct.html '//*[@class="sidebar-links"]/a[@href="#method.some_fn-1"]' \
// @has foo/struct.SomeStruct.html '//*[@class="sidebar-elems"]//section//li/a[@href="#method.some_fn-1"]' \
// "some_fn"
pub struct SomeStruct<T> { _inner: T }

Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/sidebar-links-to-foreign-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// @has foo/trait.Foo.html
// @has - '//*[@class="sidebar-title"]/a[@href="#foreign-impls"]' 'Implementations on Foreign Types'
// @has - '//h2[@id="foreign-impls"]' 'Implementations on Foreign Types'
// @has - '//*[@class="sidebar-links"]/a[@href="#impl-Foo-for-u32"]' 'u32'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#impl-Foo-for-u32"]' 'u32'
// @has - '//*[@id="impl-Foo-for-u32"]//h3[@class="code-header in-band"]' 'impl Foo for u32'
// @has - '//*[@class="sidebar-links"]/a[@href="#impl-Foo-for-%26%27a%20str"]' "&'a str"
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#impl-Foo-for-%26%27a%20str"]' "&'a str"
// @has - '//*[@id="impl-Foo-for-%26%27a%20str"]//h3[@class="code-header in-band"]' "impl<'a> Foo for &'a str"
pub trait Foo {}

Expand Down