rust-lang / rust-lang/rustfmt

Extra blank line inserted before code blocks in doc comments

Open
#6,695 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

only-with-option S-fixed-needs-subtree-sync UO-wrap_comments
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

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.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.