Skip to content

format_code_in_doc_comments should not touch non-rust code blocks #6609

@joshtriplett

Description

@joshtriplett

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

Metadata

Metadata

Labels

a-commentse-trailing whitespaceerror[internal]: left behind trailing whitespaceonly-with-optionrequires a non-default option value to reproduce

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions