Skip to content

Non-idempotency in consecutive block comment #7019

Description

@jieyouxu

Summary

Reported in #6639 (comment) by @yuxqiu, split out to its own issue.

I tried to format this code:

fn f() -> usize {
    /*A*/ /*B*/
    1 + 2
}

Expected behavior

I expected to see this happen: be idempotent.

Actual behavior

Instead, this happened: formatting is non-idempotent and takes 2 steps to converge:

start

fn f() -> usize {
    /*A*/ /*B*/
    1 + 2
}

start -> form 1

fn f() -> usize {
    /*A*/
 /*B*/
    1 + 2
}

form 1 -> form 2

fn f() -> usize {
    /*A*/
    /*B*/
    1 + 2
}

Configuration

rustfmt cli options used (if applicable):

$ rustfmt +stable --config-path=/dev/null

rustfmt configuration file (e.g. rustfmt.toml, if applicable): none

Reproduction Steps

$ cat foo.rs
fn f() -> usize {
    /*A*/ /*B*/
    1 + 2
}

$ rustfmt +stable --config-path=/dev/null foo.rs # step 1
$ cat foo.rs
fn f() -> usize {
    /*A*/
 /*B*/
    1 + 2
}

$ rustfmt +stable --config-path=/dev/null foo.rs # step 2
$ cat foo.rs
fn f() -> usize {
    /*A*/
    /*B*/
    1 + 2
}

Meta

rustfmt --version:

rustfmt 1.9.0-stable (8bab26f4f6 2026-07-14)

Metadata

Metadata

Assignees

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-non-idempotencyIssue: non-idempotency (different formatting outcomes even though unchanged by user)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions