Skip to content

Rustdoc: Visual indentation of function return type looks funky #40687

Closed
@killercup

Description

@killercup

I have a function with this signature:

pub fn extract_code_blocks<'md, I: Iterator<Item=Event<'md>>>(md_events: I) -> Result<Vec<CodeBlock>, Error>

So far so good. In the original source, it's all on one line, but Rustdoc uses quite a large font, so it makes sense to split it up. The problem is with the way it tries to reformat the signature, i.e., by putting the return type directly beneath the opening bracket of the arguments:

bildschirmfoto 2017-03-20 um 22 05 26

And while it doesn't look great on a wide screen, resizing the window makes it look just broken:

bildschirmfoto 2017-03-20 um 22 05 31

bildschirmfoto 2017-03-20 um 22 05 38

To get a good idea how to format functions it might be wise to check the discussion of the fmt team in rust-lang/style-team#39, but I don't think Rustdoc has the same constraints as rustfmt.

In particular, I would render the function signature quoted above as:

pub fn extract_code_blocks<'md, I: Iterator<Item=Event<'md>>>(
    md_events: I,
) -> Result<Vec<CodeBlock>, Error>

alternatively,

pub fn extract_code_blocks<'md, I: Iterator<Item=Event<'md>>>
    (md_events: I)
    -> Result<Vec<CodeBlock>, Error>

or even (introducing where clauses):

pub fn extract_code_blocks<'md, I>(md_events: I)
    -> Result<Vec<CodeBlock>, Error>
    where I: Iterator<Item=Event<'md>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions