You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)).
541
541
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:
543
544
544
545
```toml
545
546
edition = "2024"
@@ -2752,6 +2753,17 @@ Controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338]
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.
Copy file name to clipboardExpand all lines: README.md
+19-3Lines changed: 19 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -170,14 +170,30 @@ See [GitHub page](https://rust-lang.github.io/rustfmt/) for details.
170
170
171
171
### Rust's Editions
172
172
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.
174
177
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:
176
179
177
180
```toml
178
181
edition = "2024"
179
182
```
180
183
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
+
181
197
## Tips
182
198
183
199
* For things you do not want rustfmt to mangle, use `#[rustfmt::skip]`
@@ -224,7 +240,7 @@ edition = "2024"
224
240
| checkstyle | emits in a checkstyle format | Yes |
225
241
| json | emits diffs in a json format | Yes |
226
242
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.
0 commit comments