Skip to content

Commit 6bcadd6

Browse files
committed
Merge remote-tracking branch 'upstream/master' into subtree-push-nightly-2024-08-17
2 parents 7b2299a + fbe0424 commit 6bcadd6

File tree

153 files changed

+2731
-1073
lines changed

Some content is hidden

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

153 files changed

+2731
-1073
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased]
44

5+
## [1.7.1] 2024-06-24
6+
57
### Fixed
68

79
- Fix an idempotency issue when rewriting where clauses in which rustfmt would continuously add a trailing comma `,` to the end of trailing line comments [#5941](https://github.com/rust-lang/rustfmt/issues/5941).
@@ -238,7 +240,7 @@
238240

239241
### Added
240242

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)
243+
- 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)
242244

243245
### Misc
244246

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`

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

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)