Skip to content

Commit 3955c2e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into subtree-push-nightly-2025-04-02
2 parents 1963641 + f371e16 commit 3955c2e

File tree

177 files changed

+3351
-644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+3351
-644
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
use std::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64};
4040
```
4141
[style guide's version sorting algorithm]: https://doc.rust-lang.org/nightly/style-guide/#sorting
42-
- When parsing rustfmt configurations fails, rustfmt will now include the path to the toml file in the erorr message [#6302](https://github.com/rust-lang/rustfmt/issues/6302)
42+
- When parsing rustfmt configurations fails, rustfmt will now include the path to the toml file in the error message [#6302](https://github.com/rust-lang/rustfmt/issues/6302)
4343

4444
### Added
4545
- rustfmt now formats trailing where clauses in type aliases [#5887](https://github.com/rust-lang/rustfmt/pull/5887)
@@ -133,7 +133,7 @@
133133
### Changed
134134

135135
- `hide_parse_errors` has been soft deprecated and it's been renamed to `show_parse_errors` [#5961](https://github.com/rust-lang/rustfmt/pull/5961).
136-
- The diff output produced by `rustfmt --check` is more compatable with editors that support navigating directly to line numbers [#5971](https://github.com/rust-lang/rustfmt/pull/5971)
136+
- The diff output produced by `rustfmt --check` is more compatible with editors that support navigating directly to line numbers [#5971](https://github.com/rust-lang/rustfmt/pull/5971)
137137
- When using `version=Two`, the `trace!` macro from the [log crate] is now formatted similarly to `debug!`, `info!`, `warn!`, and `error!` [#5987](https://github.com/rust-lang/rustfmt/issues/5987).
138138

139139
[log crate]: https://crates.io/crates/log

Cargo.lock

+20-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ rustfmt-format-diff = []
3333
generic-simd = ["bytecount/generic-simd"]
3434

3535
[dependencies]
36-
annotate-snippets = { version = "0.9", features = ["color"] }
36+
annotate-snippets = { version = "0.11" }
3737
anyhow = "1.0"
3838
bytecount = "0.6.8"
3939
cargo_metadata = "0.18"
@@ -57,6 +57,7 @@ unicode-width = "0.1"
5757
unicode-properties = { version = "0.1", default-features = false, features = ["general-category"] }
5858

5959
rustfmt-config_proc_macro = { version = "0.3", path = "config_proc_macro" }
60+
semver = "1.0.21"
6061

6162
# Rustc dependencies are loaded from the sysroot, Cargo doesn't know about them.
6263

Configurations.md

+128-6
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,17 @@ Specifies which edition is used by the parser.
537537
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"`
538538
- **Stable**: Yes
539539

540-
Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed
541-
through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition needs to be specified
542-
in your config file:
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+
542+
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`.
543+
For example in your `rustfmt.toml` file:
543544

544545
```toml
545546
edition = "2018"
546547
```
547548

549+
Alternatively, you can use the `--edition` flag when running `rustfmt` directly.
550+
548551
## `empty_item_single_line`
549552

550553
Put empty-body functions and impls on a single line
@@ -1256,6 +1259,56 @@ Control the case of the letters in hexadecimal literal values
12561259
- **Possible values**: `Preserve`, `Upper`, `Lower`
12571260
- **Stable**: No (tracking issue: [#5081](https://github.com/rust-lang/rustfmt/issues/5081))
12581261

1262+
## `float_literal_trailing_zero`
1263+
1264+
Control the presence of trailing zero in floating-point literal values
1265+
1266+
- **Default value**: `Preserve`
1267+
- **Possible values**: `Preserve`, `Always`, `IfNoPostfix`, `Never`
1268+
- **Stable**: No (tracking issue: [#6471](https://github.com/rust-lang/rustfmt/issues/6471))
1269+
1270+
#### `Preserve` (default):
1271+
1272+
Leave the literal as-is.
1273+
1274+
```rust
1275+
fn main() {
1276+
let values = [1.0, 2., 3.0e10, 4f32];
1277+
}
1278+
```
1279+
1280+
#### `Always`:
1281+
1282+
Add a trailing zero to the literal:
1283+
1284+
```rust
1285+
fn main() {
1286+
let values = [1.0, 2.0, 3.0e10, 4.0f32];
1287+
}
1288+
```
1289+
1290+
#### `IfNoPostfix`:
1291+
1292+
Add a trailing zero by default. If the literal contains an exponent or a suffix, the zero
1293+
and the preceding period are removed:
1294+
1295+
```rust
1296+
fn main() {
1297+
let values = [1.0, 2.0, 3e10, 4f32];
1298+
}
1299+
```
1300+
1301+
#### `Never`:
1302+
1303+
Remove the trailing zero. If the literal contains an exponent or a suffix, the preceding
1304+
period is also removed:
1305+
1306+
```rust
1307+
fn main() {
1308+
let values = [1., 2., 3e10, 4f32];
1309+
}
1310+
```
1311+
12591312
## `hide_parse_errors`
12601313

12611314
This option is deprecated and has been renamed to `show_parse_errors` to avoid confusion around the double negative default of `hide_parse_errors=false`.
@@ -2362,9 +2415,62 @@ Require a specific version of rustfmt. If you want to make sure that the
23622415
specific version of rustfmt is used in your CI, use this option.
23632416

23642417
- **Default value**: `CARGO_PKG_VERSION`
2365-
- **Possible values**: any published version (e.g. `"0.3.8"`)
2418+
- **Possible values**: `semver` compliant values, such as defined on [semver.org](https://semver.org/).
23662419
- **Stable**: No (tracking issue: [#3386](https://github.com/rust-lang/rustfmt/issues/3386))
23672420

2421+
#### Match on exact version:
2422+
2423+
```toml
2424+
required_version="1.0.0"
2425+
```
2426+
2427+
#### Higher or equal to:
2428+
2429+
```toml
2430+
required_version=">=1.0.0"
2431+
```
2432+
2433+
#### Lower or equal to:
2434+
2435+
```toml
2436+
required_version="<=1.0.0"
2437+
```
2438+
2439+
#### New minor or patch versions:
2440+
2441+
```toml
2442+
required_version="^1.0.0"
2443+
```
2444+
2445+
#### New patch versions:
2446+
2447+
```toml
2448+
required_version="~1.0.0"
2449+
```
2450+
2451+
#### Wildcard:
2452+
2453+
```toml
2454+
required_version="*" # matches any version.
2455+
required_version="1.*" # matches any version with the same major version
2456+
required_version="1.0.*" # matches any version with the same major and minor version
2457+
```
2458+
2459+
#### Multiple versions to match:
2460+
2461+
A comma separated list of version requirements.
2462+
The match succeeds when the current rustfmt version matches all version requirements.
2463+
2464+
The one notable exception is that a wildcard matching any version cannot be used in the list.
2465+
For example, `*, <1.0.0` will always fail.
2466+
2467+
Additionally, the version match will always fail if any of the version requirements contradict themselves.
2468+
Some examples of contradictory requirements are `1.*, >2.0.0`, `1.0.*, >2.0.0` and `<1.5.0, >1.10.*`.
2469+
2470+
```toml
2471+
required_version=">=1.0.0, <2.0.0"
2472+
```
2473+
23682474
## `short_array_element_width_threshold`
23692475

23702476
The width threshold for an array element to be considered "short".
@@ -2700,6 +2806,20 @@ Controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338]
27002806
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"` (unstable variant)
27012807
- **Stable**: No
27022808

2809+
This option is inferred from the [`edition`](#edition) if not specified.
2810+
2811+
See [Rust Style Editions] for details on formatting differences between style editions.
2812+
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.
2813+
2814+
To ensure consistent formatting, it is recommended to specify the `style_edition` in a `rustfmt.toml` configuration file. For example:
2815+
2816+
```toml
2817+
style_edition = "2024"
2818+
```
2819+
2820+
Alternatively, you can use the `--style-edition` flag when running `rustfmt` directly.
2821+
2822+
[Rust Style Editions]: https://doc.rust-lang.org/nightly/style-guide/editions.html?highlight=editions#rust-style-editions
27032823
[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/
27042824
[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html
27052825

@@ -3062,7 +3182,9 @@ fn main() {
30623182

30633183
## `version`
30643184

3065-
This option is deprecated and has been replaced by [`style_edition`](#style_edition)
3185+
This option is deprecated and has been replaced by [`style_edition`](#style_edition).
3186+
`version = "One"` is equivalent to `style_edition = "(2015|2018|2021)"` and
3187+
`version = "Two"` is equivalent to `style_edition = "2024"`
30663188

30673189
- **Default value**: `One`
30683190
- **Possible values**: `One`, `Two`
@@ -3112,7 +3234,7 @@ Break comments to fit on the line
31123234

31133235
Note that no wrapping will happen if:
31143236
1. The comment is the start of a markdown header doc comment
3115-
2. An URL was found in the comment
3237+
2. A URL was found in the comment
31163238

31173239
- **Default value**: `false`
31183240
- **Possible values**: `true`, `false`

README.md

+27-3
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,36 @@ See [GitHub page](https://rust-lang.github.io/rustfmt/) for details.
170170

171171
### Rust's Editions
172172

173-
Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if
174-
executed through the Cargo's formatting tool `cargo fmt`. Otherwise, the edition
175-
needs to be specified in `rustfmt.toml`, e.g., with `edition = "2018"`.
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+
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`.
176+
For example in your `rustfmt.toml` file:
177+
178+
```toml
179+
edition = "2018"
180+
```
181+
182+
### Style Editions
183+
184+
This option is inferred from the [`edition`](#rusts-editions) if not specified.
185+
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.
188+
189+
To ensure consistent formatting, it is recommended to specify the `style_edition` in a `rustfmt.toml` configuration file. For example:
190+
191+
```toml
192+
style_edition = "2024"
193+
```
194+
[Rust Style Editions]: https://doc.rust-lang.org/nightly/style-guide/editions.html?highlight=editions#rust-style-editions
195+
[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/
196+
[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html
176197

177198
## Tips
178199

200+
* To ensure consistent parsing between `cargo fmt` and `rustfmt`, you should configure the [`edition`](#rusts-editions) in your `rustfmt.toml` file.
201+
* To ensure consistent formatting between `cargo fmt` and `rustfmt`, you should configure the [`style_edition`](#style-editions) in your `rustfmt.toml` file.
202+
179203
* For things you do not want rustfmt to mangle, use `#[rustfmt::skip]`
180204
* To prevent rustfmt from formatting a macro or an attribute,
181205
use `#[rustfmt::skip::macros(target_macro_name)]` or

0 commit comments

Comments
 (0)