Skip to content

format_code_in_doc_comments should not touch non-rust code blocks #6609

Open

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.

Activity

  1. ytmimi commented on Jul 21, 2025

    @ytmimi
    Contributor

    Related to #6015 because that example also shows rustfmt modifying ```text blocks.

  2. added
    E-needs-mcveCall for participation: this issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Jul 21, 2025
  3. ytmimi commented on Jul 21, 2025

    @ytmimi
    Contributor

    @joshtriplett when you have a moment can you post a code snippet we can use to verify this. Also can you post what version of rustfmt you're using and any other additional configs besides format_code_in_doc_comments that you might be using?

  4. joshtriplett commented on Jul 21, 2025

    @joshtriplett
    MemberAuthor

    @ytmimi Added an MCVE, and corrected the description of the problem.

  5. added
    only-with-optionRequires a non-default option value to reproduce
    I-trailing-whitespaceIssue: internal error; left behind trailing whitespace
    and removed
    E-needs-mcveCall for participation: this issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Jul 22, 2025
  6. matthewhughes934 commented on Jul 22, 2025

    @matthewhughes934
    Contributor

    Hi! I've not contributed to this repo before, but I'd be interested in looking into this issue if no-one else is already

  7. calebcartwright commented on Jul 23, 2025

    @calebcartwright
    Member

    Hi! I've not contributed to this repo before, but I'd be interested in looking into this issue if no-one else is already

    That'd be great. I'm not aware of anyone actively working on this, so feel free to claim (tag rustbot user with the claim command in a comment on the issue)

  8. matthewhughes934 commented on Jul 23, 2025

    @matthewhughes934
    Contributor

    great! In that case:

    @rustbot claim

  9. added a commit that references this issue on Jul 25, 2025
    a44f0e8
  10. matthewhughes934 commented on Jul 25, 2025

    @matthewhughes934
    Contributor

    my attempt: #6615

  11. added a commit that references this issue on Jan 21, 2026
    9242949
  12. added
    C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE
    on Feb 25, 2026
  13. added a commit that references this issue on Feb 25, 2026
    0a9f14d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-commentsArea: commentsC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEI-trailing-whitespaceIssue: internal error; left behind trailing whitespaceUO-format_code_in_doc_commentsUnstable option: format_code_in_doc_commentsonly-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