Skip to content

Commit

Permalink
docs: more accurate docs about editon and style_edition options
Browse files Browse the repository at this point in the history
Co-authored-by: Yacin Tmimi <yacintmimi@gmail.com>
  • Loading branch information
karolzwolak and ytmimi authored Feb 27, 2025
1 parent 21852b6 commit 57e11a7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ Specifies which edition is used by the parser.

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)).

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.
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`.
For example in your `rustfmt.toml` file:

```toml
Expand Down Expand Up @@ -2808,10 +2808,10 @@ Controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338]

This option is inferred from the [`edition`](#edition) if not specified.

See [Rust Style Editions] for details on style editions.
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.
See [Rust Style Editions] for details on formatting differences between style editions.
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.

To ensure consistent formatting, it is recommended to specify the [`edition`](#edition) or `style_edition` in a `rustfmt.toml` configuration file. For example:
To ensure consistent formatting, it is recommended to specify the `style_edition` in a `rustfmt.toml` configuration file. For example:

```toml
style_edition = "2024"
Expand Down

0 comments on commit 57e11a7

Please sign in to comment.