Skip to content

Commit 0fa28a7

Browse files
committed
docs: clarify the editions behavior and it's consequences on formatting
1 parent 2ad782c commit 0fa28a7

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

Configurations.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,16 @@ Specifies which edition is used by the parser.
537537
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"`
538538
- **Stable**: Yes
539539

540-
Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed
541-
through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition needs to be specified
542-
in your config file:
540+
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.
541+
542+
To ensure consistent formatting, it is recommended to specify the edition in a `rustfmt.toml` configuration file. For example:
543543

544544
```toml
545-
edition = "2018"
545+
edition = "2024"
546546
```
547547

548+
Alternatively, you can use the `--edition` flag when running `rustfmt` directly.
549+
548550
## `empty_item_single_line`
549551

550552
Put empty-body functions and impls on a single line

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,13 @@ See [GitHub page](https://rust-lang.github.io/rustfmt/) for details.
170170

171171
### Rust's Editions
172172

173-
Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if
174-
executed through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition
175-
needs to be specified in `rustfmt.toml`, e.g., with `edition = "2018"`.
173+
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.
174+
175+
To ensure consistent formatting, it is recommended to specify the edition in a `rustfmt.toml` configuration file. For example:
176+
177+
```toml
178+
edition = "2024"
179+
```
176180

177181
## Tips
178182

@@ -220,6 +224,8 @@ needs to be specified in `rustfmt.toml`, e.g., with `edition = "2018"`.
220224
| checkstyle | emits in a checkstyle format | Yes |
221225
| json | emits diffs in a json format | Yes |
222226

227+
* 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.
228+
223229
## License
224230

225231
Rustfmt is distributed under the terms of both the MIT license and the

0 commit comments

Comments
 (0)