Skip to content

wrap_comments can break up code snippets #5250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
imlazyeye opened this issue Mar 1, 2022 · 2 comments
Open

wrap_comments can break up code snippets #5250

imlazyeye opened this issue Mar 1, 2022 · 2 comments
Labels
a-comments a-markdown markdown formatting in doc comments only-with-option requires a non-default option value to reproduce p-low

Comments

@imlazyeye
Copy link

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).

@ytmimi
Copy link
Contributor

ytmimi commented Mar 2, 2022

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.

@ytmimi ytmimi added a-comments only-with-option requires a non-default option value to reproduce p-low labels Mar 2, 2022
@PSeitz
Copy link
Contributor

PSeitz commented Mar 11, 2022

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) 

PSeitz added a commit to PSeitz/rustfmt that referenced this issue Mar 12, 2022
Fixes rust-lang#5250 by checking if it is part of a type '::'
Add possibility to run single test
@PSeitz PSeitz mentioned this issue Mar 12, 2022
@ytmimi ytmimi added the a-markdown markdown formatting in doc comments label Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments a-markdown markdown formatting in doc comments only-with-option requires a non-default option value to reproduce p-low
Projects
None yet
Development

No branches or pull requests

3 participants