Skip to content

wrap_comments can break up code snippets #5250

Open

Description

@imlazyeye

Very related to #5244 -- not sure if this should be merged with that. Either way, a similar behavior occurs with code snippets in comments. Given the following...

/// This is a comment with some code `foo bar`.

If the comment reaches the maximum width inside the code snippet, it'll break it up like so:

/// This is a comment with some code `foo
/// bar`

I think it would be more expected for it to treat the snippet as a single lexeme, and insert the line break prior to the start (foo).

Activity

  1. ytmimi commented on Mar 2, 2022

    @ytmimi
    Contributor

    Thanks for another report!

    I just want to call out that although this has to do with wrapping code snippets, I don't necessarily know if I'd say its related to #5244. Mostly the issue here is that rustfmt doesn't do any real parsing of doc comments to figure out if it's dealing with some markdown construct. Everything is just text. Some consideration is given to markdown items that start lines (headers, lists, quotes), but the list of things that rustfmt is looking out for in comments is pretty small.

    This one will be a little tricky to solve since the code snippets could appear anywhere, not just at the start of each line.

  2. PSeitz commented on Mar 11, 2022

    @PSeitz
    Contributor

    I have a similar problem when addressing types. They get split over multiple lines and are not valid links anymore

    /// [IntermediateBucketResult](crate::aggregation::intermediate_agg_result::
    /// IntermediateBucketResult) 
    
  3. added a commit that references this issue on Mar 12, 2022
    e0c61f5
  4. added
    A-markdownArea: markdown formatting in doc comments
    on Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-commentsArea: commentsA-markdownArea: markdown formatting in doc commentsP-lowLow priorityUO-wrap_commentsUnstable option: wrap_commentsonly-with-optionRequires a non-default option value to reproduce

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions