rust-lang / rust-lang/rustfmt

`format_code_in_doc_comments` should not touch non-rust code blocks

Open
#6,609 7 comments 0 reactions 1 assignee View on GitHub

@matthewhughes934 is already working on this.

Since Jul 23, 2025.

A-comments C-bug I-trailing-whitespace only-with-option UO-format_code_in_doc_comments
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

https://github.com/rust-lang/rustfmt/issues/3348

When format_code_in_doc_comments is enabled, rustfmt will delete trailing blank lines in non-rust code blocks (e.g. blocks prefaced with ```text), and add a trailing whitespace to leading blank lines.

/// A doc comment.
///
/// ```text
/// 
/// A text block
///    
/// ```
/// 
/// ^ A blank line
struct S;

Formatting this, with latest nightly rustfmt as of today (rustfmt 1.8.0-nightly (9982d6462b 2025-07-20)), and the format_code_in_doc_comments option, will delete the trailing blank line in the text block, and add a trailing whitespace to the leading blank line.

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.