Skip to content

Commit

Permalink
docs: correct that style_edition dictates formatting settings, not ed…
Browse files Browse the repository at this point in the history
…ition
  • Loading branch information
karolzwolak committed Feb 25, 2025
1 parent 0fa28a7 commit aa2f3ec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
16 changes: 14 additions & 2 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,10 @@ Specifies which edition is used by the parser.
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"`
- **Stable**: Yes

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

To ensure consistent formatting, it is recommended to specify the edition in a `rustfmt.toml` configuration file. For example:
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.
For example in your `rustfmt.toml` file:

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

This option is inferred from the `edition` if not specified.
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.

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

```toml
style_edition = "2024"
```

Alternatively, you can use the `--style-edition` flag when running `rustfmt` directly.

[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/
[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html

Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,30 @@ See [GitHub page](https://rust-lang.github.io/rustfmt/) for details.

### Rust's Editions

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.
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)).
By default, Rustfmt uses the `2015` 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.

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

```toml
edition = "2024"
```

### Style Editions

The option `style_edition` controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338])
It is inferred from `edition` if not explicitly set, and defaults to the `2015` edition.

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.

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

```toml
style_edition = "2024"
```

## Tips

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

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

## License

Expand Down

0 comments on commit aa2f3ec

Please sign in to comment.