Skip to content

rustdoc: awkward vertical spacing on trait bounds #85566

Closed
@jsha

Description

@jsha

When a method does not have trait bounds, it is displayed all on one line. When a method has just one trait bound, it takes four lines:

fn by_ref(&mut self) -> &mut Self
where
    Self: Sized,
{ ... }

There are some conflicting priorities here: On the one hand, it's nice for the layout to match what rustfmt does. On the other hand, it's good to use spacing to emphasize the parts of the documentation that are important. For instance, the { ... } has a whole line to itself to convey one bit of information: this is a provided method, not a required one. Spacing is also useful to show that parts of the display are related to each other. In the above, it's not visually clear whether { ... } is part of by_ref or some independent item.

I propose we change to this for methods with one trait bound:

fn by_ref(&mut self) -> &mut Self
   where Self: Sized { ... }

And this for methods with multiple trait bounds:

fn by_ref(&mut self, other: T) -> &mut Self
   where Self: Sized,
         T: Read { ... }

Screen shot of nightly: https://doc.rust-lang.org/nightly/std/io/trait.Read.html

Metadata

Metadata

Assignees

Labels

A-rustdoc-uiArea: Rustdoc UI (generated HTML)T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions