Open
Description
When group_imports = "StdExternalCrate"
is combined with imports_granularity = "Module"
, rustfmt
can format a file in a non-idempotent way, i.e. running rustfmt
twice in a row results in a different formatting.
Reduced from a case in the stdlib
(rust-lang/rust#126394).
Minimal repro:
# rustfmt.toml
version = "Two"
group_imports = "StdExternalCrate"
imports_granularity = "Module"
$ rustfmt --version
rustfmt 1.7.0-nightly (72fdf91 2024-06-05)
# file.rs
use a::c;
// foo
use a::b;
use a::d;
First run (rustfmt file.rs
):
// foo
use a::b;
use a::{c, d};
Second run (rustfmt file.rs
):
// foo
use a::{b, c, d};
Removing the group_imports
or imports_granularity
options removes the issue. The problem seems to be caused by the comment, without it it works fine.