Rollup merge of #83337 - Manishearth:item-hide, r=GuillaumeGomez

rustdoc: Hide item contents, not items

This tweaks rustdoc to hide item contents instead of items, and only when there are too many of them.

This means that users will _always_ see the type parameters, and will _often_ see fields/etc as long as they are small. Traits have some heuristics for hiding only the methods or only the methods and the consts, since the associated types are super important.

I'm happy to play around with the heuristics here; we could potentially make it so that structs/enums/etc are always hidden but traits will try really hard to show type aliases.

This needs a test, but you can see it rendered at https://manishearth.net/sand/doc_render/bar/

<details>

<summary> Code example </summary>

```rust
pub struct PubStruct {
    pub a: usize,
    pub b: usize,
}

pub struct BigPubStruct {
    pub a: usize,
    pub b: usize,
    pub c: usize,
    pub d: usize,
    pub e: usize,
    pub f: usize,
}

pub union BigUnion {
    pub a: usize,
    pub b: usize,
    pub c: usize,
    pub d: usize,
    pub e: usize,
    pub f: usize,
}

pub union Union {
    pub a: usize,
    pub b: usize,
    pub c: usize,
}

pub struct PrivStruct {
    a: usize,
    b: usize,
}

pub enum Enum {
    A, B, C,
    D {
        a: u8,
        b: u8
    }
}

pub enum LargeEnum {
    A, B, C, D, E, F, G, H, I, J
}

pub trait Trait {
    type A;
    #[must_use]
    fn foo();
    fn bar();
}

pub trait GinormousTrait {
    type A;
    type B;
    type C;
    type D;
    type E;
    type F;
    const N: usize = 1;
    #[must_use]
    fn foo();
    fn bar();
}

pub trait HugeTrait {
    type A;
    const M: usize = 1;
    const N: usize = 1;
    const O: usize = 1;
    const P: usize = 1;
    const Q: usize = 1;
    #[must_use]
    fn foo();
    fn bar();
}

pub trait BigTrait {
    type A;
    #[must_use]
    fn foo();
    fn bar();
    fn baz();
    fn quux();
    fn frob();
    fn greeble();
}

#[macro_export]
macro_rules! foo {
    (a) => {a};
}
```

</details>

Fixes https://github.com/rust-lang/rust/issues/82114
This commit is contained in:
Dylan DPC
2021-04-16 14:08:30 +02:00
committed by GitHub
11 changed files with 347 additions and 154 deletions

View File

@@ -1056,12 +1056,6 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
margin-top: 3px;
}
.enum > .toggle-wrapper + .docblock, .struct > .toggle-wrapper + .docblock {
margin-left: 30px;
margin-bottom: 20px;
margin-top: 5px;
}
.docblock > .section-header:first-child {
margin-left: 15px;
margin-top: 0;
@@ -1071,30 +1065,10 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
left: -10px;
}
.enum > .collapsed, .struct > .collapsed {
margin-bottom: 25px;
}
#main > .variant, #main > .structfield {
display: block;
}
.attributes {
display: block;
margin-top: 0px !important;
margin-right: 0px;
margin-bottom: 0px !important;
margin-left: 30px;
}
.toggle-attributes.collapsed {
margin-bottom: 0;
}
.impl-items > .toggle-attributes {
margin-left: 20px;
}
.impl-items .attributes {
font-weight: 500;
}
:target > code {
opacity: 1;
@@ -1781,16 +1755,54 @@ div.name.expand::before {
top: 2px;
}
/* This part is to fix the "Expand attributes" part in the type declaration. */
.type-decl > pre > .toggle-wrapper.toggle-attributes.top-attr {
margin-left: 0 !important;
/* The hideme class is used on summary tags that contain a span with
placeholder text shown only when the toggle is closed. For instance,
"Expand description" or "Show methods". */
details.rustdoc-toggle > summary.hideme {
cursor: pointer;
}
.type-decl > pre > .docblock.attributes.top-attr {
margin-left: 1.8em !important;
details.rustdoc-toggle > summary::-webkit-details-marker {
display: none;
}
.type-decl > pre > .toggle-attributes {
margin-left: 2.2em;
details.rustdoc-toggle > summary.hideme > span {
margin-left: 9px;
}
.type-decl > pre > .docblock.attributes {
margin-left: 4em;
details.rustdoc-toggle > summary::before {
content: "[+]";
font-weight: 300;
font-size: 0.8em;
letter-spacing: 1px;
}
details.rustdoc-toggle > summary.hideme::before {
position: relative;
}
details.rustdoc-toggle > summary:not(.hideme)::before {
float: left;
}
/* When a "hideme" summary is open and the "Expand description" or "Show
methods" text is hidden, we want the [-] toggle that remains to not
affect the layout of the items to its right. To do that, we use
absolute positioning. Note that we also set position: relative
on the parent <details> to make this work properly. */
details.rustdoc-toggle[open] > summary.hideme {
position: absolute;
}
details.rustdoc-toggle[open] {
position: relative;
}
details.rustdoc-toggle[open] > summary.hideme > span {
display: none;
}
details.rustdoc-toggle[open] > summary::before {
content: "[]";
display: inline;
}