diff --git a/Configurations.md b/Configurations.md index e27c40ff0df..c0c1290d63b 100644 --- a/Configurations.md +++ b/Configurations.md @@ -537,14 +537,16 @@ Specifies which edition is used by the parser. - **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"` - **Stable**: Yes -Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed -through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition needs to be specified -in your config file: +Starting with the 2024 edition, Rust introduced changes to default formatting. This can lead to inconsistencies between `rustfmt` and `cargo fmt` if the edition is not explicitly configured. This is because `cargo fmt` automatically picks up the edition from `Cargo.toml`, while `rustfmt` defaults to the `2015` edition unless otherwise specified. + +To ensure consistent formatting, it is recommended to specify the edition in a `rustfmt.toml` configuration file. For example: ```toml -edition = "2018" +edition = "2024" ``` +Alternatively, you can use the `--edition` flag when running `rustfmt` directly. + ## `empty_item_single_line` Put empty-body functions and impls on a single line diff --git a/README.md b/README.md index b68a942e463..ffaa5f74fca 100644 --- a/README.md +++ b/README.md @@ -170,9 +170,13 @@ See [GitHub page](https://rust-lang.github.io/rustfmt/) for details. ### Rust's Editions -Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if -executed through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition -needs to be specified in `rustfmt.toml`, e.g., with `edition = "2018"`. +Starting with the 2024 edition, Rust introduced changes to default formatting. This can lead to inconsistencies between `rustfmt` and `cargo fmt` if the edition is not explicitly configured. This is because `cargo fmt` automatically picks up the edition from `Cargo.toml`, while `rustfmt` defaults to the `2015` edition unless otherwise specified. + +To ensure consistent formatting, it is recommended to specify the edition in a `rustfmt.toml` configuration file. For example: + +```toml +edition = "2024" +``` ## Tips @@ -220,6 +224,8 @@ needs to be specified in `rustfmt.toml`, e.g., with `edition = "2018"`. | checkstyle | emits in a checkstyle format | Yes | | json | emits diffs in a json format | Yes | +* When using `rustfmt` directly in a Cargo project, set the `edition` in `rustfmt.toml` to the same value as in `Cargo.toml` to ensure consistent formatting. For more details, see the [Rust's Editions](#rusts-editions) section. + ## License Rustfmt is distributed under the terms of both the MIT license and the