Skip to content

Commit aa2f3ec

Browse files
committed
docs: correct that style_edition dictates formatting settings, not edition
1 parent 0fa28a7 commit aa2f3ec

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

Configurations.md

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

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.
540+
The `edition` option determines the Rust language edition used for parsing the code. This is important for syntax compatibility but does not directly control formatting behavior (see [style_edition](#style_edition)).
541541

542-
To ensure consistent formatting, it is recommended to specify the edition in a `rustfmt.toml` configuration file. For example:
542+
When running `cargo fmt`, the `edition` is automatically inferred from the `Cargo.toml` file. However, when running `rustfmt` directly, the `edition` must be explicitly set in the configuration file or via the command line.
543+
For example in your `rustfmt.toml` file:
543544

544545
```toml
545546
edition = "2024"
@@ -2752,6 +2753,17 @@ Controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338]
27522753
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"` (unstable variant)
27532754
- **Stable**: No
27542755

2756+
This option is inferred from the `edition` if not specified.
2757+
Starting with the 2024 edition, Rust introduced changes to default formatting. This can lead to inconsistencies between `rustfmt` and `cargo fmt` if the style 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.
2758+
2759+
To ensure consistent formatting, it is recommended to specify the `edition` or `style_edition` in a `rustfmt.toml` configuration file. For example:
2760+
2761+
```toml
2762+
style_edition = "2024"
2763+
```
2764+
2765+
Alternatively, you can use the `--style-edition` flag when running `rustfmt` directly.
2766+
27552767
[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/
27562768
[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html
27572769

README.md

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

171171
### Rust's Editions
172172

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.
173+
The `edition` option determines the Rust language edition used for parsing the code. This is important for syntax compatibility but does not directly control formatting behavior (see [Style Editions](#style-editions)).
174+
By default, Rustfmt uses the `2015` edition.
175+
176+
When running `cargo fmt`, the `edition` is automatically inferred from the `Cargo.toml` file. However, when running `rustfmt` directly, the `edition` must be explicitly set in the configuration file or via the command line.
174177

175-
To ensure consistent formatting, it is recommended to specify the edition in a `rustfmt.toml` configuration file. For example:
178+
For example in your `rustfmt.toml` file:
176179

177180
```toml
178181
edition = "2024"
179182
```
180183

184+
### Style Editions
185+
186+
The option `style_edition` controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338])
187+
It is inferred from `edition` if not explicitly set, and defaults to the `2015` edition.
188+
189+
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.
190+
191+
To ensure consistent formatting, it is recommended to specify the `edition` or `style_edition` in a `rustfmt.toml` configuration file. For example:
192+
193+
```toml
194+
style_edition = "2024"
195+
```
196+
181197
## Tips
182198

183199
* For things you do not want rustfmt to mangle, use `#[rustfmt::skip]`
@@ -224,7 +240,7 @@ edition = "2024"
224240
| checkstyle | emits in a checkstyle format | Yes |
225241
| json | emits diffs in a json format | Yes |
226242

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.
243+
* When using `rustfmt` directly in a Cargo project, set the `style_edition` or `edition` in `rustfmt.toml` to the same value as in `Cargo.toml` to ensure consistent formatting. For more details, see the [Style Editions](#style-editions) and [Rust's Editions](#rusts-editions) sections.
228244

229245
## License
230246

0 commit comments

Comments
 (0)