Common well-known traits make "Trait Implementations" too verbose

cc115fa
Opened by Kornel at 2022-01-18 22:16:13

I find the "Trait Implementations" section of Rustdoc very hard to follow. It has low signal to noise ratio:

  • Very common traits are displayed in full detail. For traits like Copy, Clone, Default, Display, Debug, Hash, etc. I don't need to see all the methods inline with their description. Just links to these traits would be enough. Generally I only need to know whether the type implements them or not.

  • Similarly, traits used via operators are also displayed in full detail. Eq, PartialEq, Add, Sub, Ord, PartialOrd, etc. flood the documentation page with documentation of the traits, and the specific methods are even less relevant. The long verbose list makes it hard to see which traits are supported.

  • If the type implements the same trait multiple times for slightly different types, the whole trait documentation is repeated multiple times. It is useful to know which type combinations are supported, but repeated function descriptions only lower signal to noise ratio. It's worst for primitive types where the list appears to be dominated by countless the variants of Shr and Shl, drowning out all other information.

The current layout does work well for less common/more specific traits, e.g. having entire trait documentation inlined is perfect for *Ext traits and makes sense in some cases like impl Read for File.

So I'm suggesting:

  • Implement collapsing widget for trait implementations, which collapses documentation of methods, leaving only [+] impl Trait for Foo line.

  • Collapse basic traits by default (Copy, Clone, Debug, std::ops::*, etc.). Not all traits in std are obvious, so the list of traits to display in a terse form would probably be manually curated.

  • Group implementations of the same trait together, and collapse all implementations except one. For example File displays all of Read docs twice, in two separate places. It makes the list longer and makes it harder to notice that there are two implementations. It would be clearer to display it as:

    [+] impl Read for File [-] impl<'a> Read for &'a File fn read(&mut self) …

  1. cc @rust-lang/docs

    Guillaume Gomez at 2017-03-15 11:18:32

  2. Implement collapsing widget for trait implementations, which collapses documentation of methods, leaving only [+] impl Trait for Foo line.

    Thinking about implementing this.

    Vitaly Shukela at 2018-01-29 13:20:16

  3. Is there some exhausive list or traits (in std or maybe across the entire ecosystem) that should be collapsed by default?

    Vitaly Shukela at 2018-01-31 14:30:30

  4. I'd look through std::ops, as these are the noisiest.

    Kornel at 2018-01-31 15:02:06

  5. It is also suggested just to collapse all impls items by default. It is simpler.

    Vitaly Shukela at 2018-01-31 15:04:58