Skip to content

Commit 14f12fb

Browse files
committed
docs: ensure consistency between readme and configuration docs on editions
1 parent ecf3b62 commit 14f12fb

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,22 @@ See [GitHub page](https://rust-lang.github.io/rustfmt/) for details.
171171
### Rust's Editions
172172

173173
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.
177174

175+
When running `cargo fmt`, the `edition` is automatically read from the `Cargo.toml` file. However, when running `rustfmt` directly the `edition` defaults to 2015 if not explicitly configured. For consistent parsing between rustfmt and `cargo fmt` you should configure the `edition`.
178176
For example in your `rustfmt.toml` file:
179177

180178
```toml
181-
edition = "2024"
179+
edition = "2018"
182180
```
183181

184182
### Style Editions
185183

186-
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.
184+
This option is inferred from the [`edition`](#rusts-editions) if not specified.
188185

189-
See [Rust Style Editions] for details on style editions.
190-
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.
186+
See [Rust Style Editions] for details on formatting differences between style editions.
187+
rustfmt has a default style edition of `2015` while `cargo fmt` infers the style edition from the `edition` set in `Cargo.toml`. This can lead to inconsistencies between `rustfmt` and `cargo fmt` if the style edition is not explicitly configured.
191188

192-
To ensure consistent formatting, it is recommended to specify the `edition` or `style_edition` in a `rustfmt.toml` configuration file. For example:
189+
To ensure consistent formatting, it is recommended to specify the `style_edition` in a `rustfmt.toml` configuration file. For example:
193190

194191
```toml
195192
style_edition = "2024"

0 commit comments

Comments
 (0)