Skip to content

Commit 2e45ec3

Browse files
committed
Auto merge of rust-lang#130593 - ytmimi:sync-from-rustfmt, r=ytmimi
Sync from rustfmt r? `@ghost`
2 parents 5793a9e + eeda9dd commit 2e45ec3

File tree

197 files changed

+4709
-1557
lines changed

Some content is hidden

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

197 files changed

+4709
-1557
lines changed

Diff for: Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -4630,7 +4630,7 @@ dependencies = [
46304630

46314631
[[package]]
46324632
name = "rustfmt-nightly"
4633-
version = "1.7.1"
4633+
version = "1.8.0"
46344634
dependencies = [
46354635
"annotate-snippets 0.9.2",
46364636
"anyhow",

Diff for: src/tools/rustfmt/.github/workflows/check_diff.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
steps:
2323
- name: checkout
24-
uses: actions/checkout@v3
24+
uses: actions/checkout@v4
2525

2626
- name: install rustup
2727
run: |

Diff for: src/tools/rustfmt/.github/workflows/integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464

6565
steps:
6666
- name: checkout
67-
uses: actions/checkout@v3
67+
uses: actions/checkout@v4
6868

6969
# Run build
7070
- name: install rustup

Diff for: src/tools/rustfmt/.github/workflows/linux.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626

2727
steps:
2828
- name: checkout
29-
uses: actions/checkout@v3
29+
uses: actions/checkout@v4
3030

3131
# Run build
3232
- name: install rustup

Diff for: src/tools/rustfmt/.github/workflows/mac.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
jobs:
99
test:
1010
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources
11-
# macOS Catalina 10.15
1211
runs-on: macos-latest
1312
name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
1413
env:
@@ -23,7 +22,7 @@ jobs:
2322

2423
steps:
2524
- name: checkout
26-
uses: actions/checkout@v3
25+
uses: actions/checkout@v4
2726

2827
# Run build
2928
- name: install rustup

Diff for: src/tools/rustfmt/.github/workflows/rustdoc_check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: rustdoc check
1212
steps:
1313
- name: checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515

1616
- name: install rustup
1717
run: |

Diff for: src/tools/rustfmt/.github/workflows/upload-assets.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
target: x86_64-pc-windows-msvc
3232
runs-on: ${{ matrix.os }}
3333
steps:
34-
- uses: actions/checkout@v3
34+
- uses: actions/checkout@v4
3535

3636
# Run build
3737
- name: install rustup

Diff for: src/tools/rustfmt/.github/workflows/windows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: disable git eol translation
3434
run: git config --global core.autocrlf false
3535
- name: checkout
36-
uses: actions/checkout@v3
36+
uses: actions/checkout@v4
3737

3838
# Run build
3939
- name: Install Rustup using win.rustup.rs

Diff for: src/tools/rustfmt/CHANGELOG.md

+62-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,66 @@
11
# Changelog
22

3-
## [Unreleased]
3+
## [1.8.0] 2024-09-20
4+
5+
### Fixed
6+
- Fix issue where rustfmt would crash on Windows when using the `ignore` option [#6178](https://github.com/rust-lang/rustfmt/issues/6178)
7+
8+
### Changed
9+
- `rustfmt --version` now prints a commit hash that is 10 characters long [#6258](https://github.com/rust-lang/rustfmt/pull/6258)
10+
- `rustfmt --version` will no longer print empty git information when git information isn't available at build time.
11+
For example, git information is not available when building rustfmt from a source tarball [#6266](https://github.com/rust-lang/rustfmt/pull/6266)
12+
- `version` has been soft deprecated and replaced by `style_edition`.
13+
`style_edition=2024` is equivalent to `version=Two` and `style_edition={2015|2018|2021}`
14+
are equivalent to `version=One` [#6247](https://github.com/rust-lang/rustfmt/pull/6247)
15+
- When `style_edition=2024` is configured `overflow_delimited_expr` will default to `true` [#6260](https://github.com/rust-lang/rustfmt/pull/6260).
16+
```rust
17+
// with style_edition=2015
18+
do_thing(
19+
x,
20+
Bar {
21+
x: value,
22+
y: value2,
23+
},
24+
);
25+
26+
// with style_edition=2024
27+
do_thing(x, Bar {
28+
x: value,
29+
y: value2,
30+
});
31+
```
32+
- When `style_edition=2024` is configured rustfmt will apply the [style guide's version sorting algorithm]
33+
when sorting imports [#6284](https://github.com/rust-lang/rustfmt/pull/6284)
34+
```rust
35+
// with style_edition=2015
36+
use std::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8};
37+
38+
// with style_edition=2024
39+
use std::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64};
40+
```
41+
[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)
43+
44+
### Added
45+
- rustfmt now formats trailing where clauses in type aliases [#5887](https://github.com/rust-lang/rustfmt/pull/5887)
46+
```rust
47+
type Foo
48+
= Bar
49+
where
50+
A: B,
51+
C: D;
52+
```
53+
- Users can now configure which `style_edition` rustfmt uses when formatting their code as specified
54+
in [RFC 3338](https://rust-lang.github.io/rfcs/3338-style-evolution.html). Users are encouraged to configure `style_edition`
55+
in their `rustfmt.toml` files, but the value can also be specified via the cli with `--unstable-features --style-edition={style_edition}`.
56+
When `style_edition` is not explicitly configured it will be inferred from the `edition` configuration.
57+
When neither `style_edition` nor `edition` are configured `style_edition` defaults to `2015` [#6247](https://github.com/rust-lang/rustfmt/pull/6247)
58+
59+
### Misc
60+
- Removed `tracing-attributes` dependency [#6208](https://github.com/rust-lang/rustfmt/pull/6208)
61+
- Reduced syn's features in the internal `config_proc_macro` crate [#6237](https://github.com/rust-lang/rustfmt/pull/6237)
62+
63+
## [1.7.1] 2024-06-24
464

565
### Fixed
666

@@ -238,7 +298,7 @@
238298

239299
### Added
240300

241-
- New configuration option (`skip_macro_invocations`)[https://rust-lang.github.io/rustfmt/?version=master&search=#skip_macro_invocations] [#5347](https://github.com/rust-lang/rustfmt/pull/5347) that can be used to globally define a single enumerated list of macro calls that rustfmt should skip formatting. rustfmt [currently also supports this via a custom tool attribute](https://github.com/rust-lang/rustfmt#tips), however, these cannot be used in all contexts because [custom inner attributes are unstable](https://github.com/rust-lang/rust/issues/54726)
301+
- New configuration option [`skip_macro_invocations`](https://rust-lang.github.io/rustfmt/?version=master&search=#skip_macro_invocations) [#5347](https://github.com/rust-lang/rustfmt/pull/5347) that can be used to globally define a single enumerated list of macro calls that rustfmt should skip formatting. rustfmt [currently also supports this via a custom tool attribute](https://github.com/rust-lang/rustfmt#tips), however, these cannot be used in all contexts because [custom inner attributes are unstable](https://github.com/rust-lang/rust/issues/54726)
242302

243303
### Misc
244304

Diff for: src/tools/rustfmt/Cargo.lock

+1-13
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ dependencies = [
499499

500500
[[package]]
501501
name = "rustfmt-nightly"
502-
version = "1.7.1"
502+
version = "1.8.0"
503503
dependencies = [
504504
"annotate-snippets",
505505
"anyhow",
@@ -710,21 +710,9 @@ checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
710710
dependencies = [
711711
"cfg-if",
712712
"pin-project-lite",
713-
"tracing-attributes",
714713
"tracing-core",
715714
]
716715

717-
[[package]]
718-
name = "tracing-attributes"
719-
version = "0.1.26"
720-
source = "registry+https://github.com/rust-lang/crates.io-index"
721-
checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
722-
dependencies = [
723-
"proc-macro2",
724-
"quote",
725-
"syn",
726-
]
727-
728716
[[package]]
729717
name = "tracing-core"
730718
version = "0.1.31"

Diff for: src/tools/rustfmt/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "rustfmt-nightly"
4-
version = "1.7.1"
4+
version = "1.8.0"
55
description = "Tool to find and fix Rust formatting issues"
66
repository = "https://github.com/rust-lang/rustfmt"
77
readme = "README.md"
@@ -50,7 +50,7 @@ serde_json = "1.0"
5050
term = "0.7"
5151
thiserror = "1.0.40"
5252
toml = "0.7.4"
53-
tracing = "0.1.37"
53+
tracing = { version = "0.1.37", default-features = false, features = ["std"] }
5454
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
5555
unicode-segmentation = "1.9"
5656
unicode-width = "0.1"

Diff for: src/tools/rustfmt/Configurations.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ Note that this option may be soft-deprecated in the future once the [ignore](#ig
534534
Specifies which edition is used by the parser.
535535

536536
- **Default value**: `"2015"`
537-
- **Possible values**: `"2015"`, `"2018"`, `"2021"`
537+
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"`
538538
- **Stable**: Yes
539539

540540
Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed
@@ -2692,6 +2692,17 @@ By default this option is set as a percentage of [`max_width`](#max_width) provi
26922692

26932693
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
26942694

2695+
## `style_edition`
2696+
2697+
Controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338])
2698+
2699+
- **Default value**: `"2015"`
2700+
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"` (unstable variant)
2701+
- **Stable**: No
2702+
2703+
[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/
2704+
[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html
2705+
26952706
## `tab_spaces`
26962707

26972708
Number of spaces per tab
@@ -3051,9 +3062,7 @@ fn main() {
30513062

30523063
## `version`
30533064

3054-
Which version of the formatting rules to use. `Version::One` is backwards-compatible
3055-
with Rustfmt 1.0. Other versions are only backwards compatible within a major
3056-
version number.
3065+
This option is deprecated and has been replaced by [`style_edition`](#style_edition)
30573066

30583067
- **Default value**: `One`
30593068
- **Possible values**: `One`, `Two`

Diff for: src/tools/rustfmt/Contributing.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ If you want to test modified `cargo-fmt`, or run `rustfmt` on the whole project
109109
RUSTFMT="./target/debug/rustfmt" cargo run --bin cargo-fmt -- --manifest-path path/to/project/you/want2test/Cargo.toml
110110
```
111111

112-
### Version-gate formatting changes
112+
### Gate formatting changes
113113

114-
A change that introduces a different code-formatting should be gated on the
115-
`version` configuration. This is to ensure the formatting of the current major
116-
release is preserved, while allowing fixes to be implemented for the next
117-
release.
114+
A change that introduces a different code-formatting must be gated on the
115+
`style_edition` configuration. This is to ensure rustfmt upholds its formatting
116+
stability guarantees and adheres to the Style Edition process set in [RFC 3338]
118117

119-
This is done by conditionally guarding the change like so:
118+
This can be done by conditionally guarding the formatting change, e.g.:
120119

121120
```rust
122-
if config.version() == Version::One { // if the current major release is 1.x
121+
// if the current stable Style Edition is Edition 2024
122+
if config.style_edition() <= StyleEdition::Edition2024 {
123123
// current formatting
124124
} else {
125125
// new formatting
@@ -129,13 +129,14 @@ if config.version() == Version::One { // if the current major release is 1.x
129129
This allows the user to apply the next formatting explicitly via the
130130
configuration, while being stable by default.
131131

132-
When the next major release is done, the code block of the previous formatting
133-
can be deleted, e.g., the first block in the example above when going from `1.x`
134-
to `2.x`.
132+
This can then be enhanced as needed if and when there are
133+
new Style Editions with differing formatting prescriptions.
135134

136135
| Note: Only formatting changes with default options need to be gated. |
137136
| --- |
138137

138+
[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html
139+
139140
### A quick tour of Rustfmt
140141

141142
Rustfmt is basically a pretty printer - that is, its mode of operation is to

Diff for: src/tools/rustfmt/build.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() {
2525
// (git not installed or if this is not a git repository) just return an empty string.
2626
fn commit_info() -> String {
2727
match (channel(), commit_hash(), commit_date()) {
28-
(channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash.trim_end(), date),
28+
(channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash, date),
2929
_ => String::new(),
3030
}
3131
}
@@ -39,17 +39,20 @@ fn channel() -> String {
3939
}
4040

4141
fn commit_hash() -> Option<String> {
42-
Command::new("git")
43-
.args(["rev-parse", "--short", "HEAD"])
42+
let output = Command::new("git")
43+
.args(["rev-parse", "HEAD"])
4444
.output()
45-
.ok()
46-
.and_then(|r| String::from_utf8(r.stdout).ok())
45+
.ok()?;
46+
let mut stdout = output.status.success().then_some(output.stdout)?;
47+
stdout.truncate(10);
48+
String::from_utf8(stdout).ok()
4749
}
4850

4951
fn commit_date() -> Option<String> {
50-
Command::new("git")
52+
let output = Command::new("git")
5153
.args(["log", "-1", "--date=short", "--pretty=format:%cd"])
5254
.output()
53-
.ok()
54-
.and_then(|r| String::from_utf8(r.stdout).ok())
55+
.ok()?;
56+
let stdout = output.status.success().then_some(output.stdout)?;
57+
String::from_utf8(stdout).ok()
5558
}

0 commit comments

Comments
 (0)