rust-lang / rust-lang/rustfmt

rustfmt cannot format code example with long `#`-hiding line

Open
#5,627 2 comments 2 reactions 1 assignee View on GitHub

@ytmimi is already working on this.

Since Dec 7, 2022.

A-comments I-poor-formatting only-with-option
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

I've had an issue with format_code_in_doc_comments for some time and decided to finally try to fix it. The issue was that some of my examples did not get formatted.

While trying to implement a fix I managed to find the cause (#) and a workaround, but I'm not able to go further. A minimal repro here

https://github.com/Emilgardis/rustfmt-no-format/blob/main/src/lib.rs

and the fix being to increase max_width (in this example to 101)

Now, the line that is problematic is

/// # let long: Fooooooooooooooooooooooooooooooooo = Fooooooooooooooooooooooooooooooooo::hi();

however, that's only 94 characters in total starting from the start of the line, not from /// .

My expectation with #-hiding in rust examples is that it should not prevent this, and in fact, removing the # you can make the line as long as you want and the other code (and the long line) gets formatted.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.