Extra blank line inserted before code blocks in doc comments
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Summary
Doc comment formatting inconsistency when using wrap_comments = true with max_width = 20: an extra blank line is inserted before code blocks.
# rustfmt.toml
wrap_comments = true
max_width = 20
/// Some doc comment with code snippet:
///```
/// '\u{1F}
/// ```
pub struct Code {}
Additional Context
This issue was discovered while attempting to fix other issues in rust-lang/rustfmt.
The latest rustfmt (rustfmt 1.8.0-nightly (6ac1fcd7a3 2025-10-09)) produces the correct output without the extra blank line. This issue is being filed to track this regression and verify whether it gets fixed after the next sync from rust-lang/rustfmt to rust-lang/rust.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running rustfmt with wrap_comments = true and max_width = 20 on the sample struct and doc comment, then compare the output with the latest rustfmt behavior described in the issue. The issue is done when formatting the sample no longer inserts an extra blank line before the code block and the regression is verified after the rust-lang/rustfmt sync.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100