-
Notifications
You must be signed in to change notification settings - Fork 963
Open
Labels
A-commentsArea: commentsArea: commentsA-importsArea: imports, e.g. `use` syntaxArea: imports, e.g. `use` syntaxC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICECategory: 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)Issue: non-idempotency (different formatting outcomes even though unchanged by user)UO-group_importsUnstable option: group_importsUnstable option: group_importsUO-imports_granularityUnstable option: imports_granularityUnstable option: imports_granularityonly-with-optionRequires a non-default option value to reproduceRequires a non-default option value to reproduce
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.
jieyouxu and ytmimi
Metadata
Metadata
Assignees
Labels
A-commentsArea: commentsArea: commentsA-importsArea: imports, e.g. `use` syntaxArea: imports, e.g. `use` syntaxC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICECategory: 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)Issue: non-idempotency (different formatting outcomes even though unchanged by user)UO-group_importsUnstable option: group_importsUnstable option: group_importsUO-imports_granularityUnstable option: imports_granularityUnstable option: imports_granularityonly-with-optionRequires a non-default option value to reproduceRequires a non-default option value to reproduce