Skip to content

rustdoc: improve word break opportunities for narrow screens #93538

Open
@jsha

Description

@jsha

On narrow screens our method signatures often wrap horribly, like this example that wraps right in the middle of a -> return arrow:

image

To fix that specific issue, we can wrap return arrows in a <span> and style that span with white-space: nowrap. There's a similar issue where the browser will break &[T] between the & and the [. We should use the same trick there to prevent breaking.

Also, the browser will never consider a parenthesis wedged between two words to be a word break opportunity. For instance, in fn foo(bar: Baz), the browser will never break between ( and bar. That's actually one of our optimal break locations; it's where rustfmt would break the word. We can tell the browser that's an available option by inserting a <wbr> tag.

Also, when we do have to break up a signature, we'd prefer to keep each parameter name on the same line as its type if possible (again, mimicking rustfmt style). We can achieve this by inserting an &nbsp; between parameter names and types. For instance bar:&nbsp;Baz. We should also use &nbsp; as the space between mut and Bar in &mut Bar. Note that this may be a little hard because that space is added by print_with_space, and the output of print_with_space is used in both HTML and non-HTML contexts.

Metadata

Metadata

Assignees

No one assigned

    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