Skip to content

Commit c048326

Browse files
committed
Auto merge of #107275 - calebcartwright:sync-from-rustfmt, r=calebcartwright
Sync rustfmt subtree
2 parents c8e6a9e + 6bf1a87 commit c048326

File tree

109 files changed

+2593
-189
lines changed

Some content is hidden

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

109 files changed

+2593
-189
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -4926,7 +4926,7 @@ dependencies = [
49264926

49274927
[[package]]
49284928
name = "rustfmt-config_proc_macro"
4929-
version = "0.2.0"
4929+
version = "0.3.0"
49304930
dependencies = [
49314931
"proc-macro2",
49324932
"quote",
@@ -4936,7 +4936,7 @@ dependencies = [
49364936

49374937
[[package]]
49384938
name = "rustfmt-nightly"
4939-
version = "1.5.1"
4939+
version = "1.5.2"
49404940
dependencies = [
49414941
"annotate-snippets",
49424942
"anyhow",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Diff Check
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
clone_url:
6+
description: 'Git url of a rustfmt fork to compare against the latest master rustfmt'
7+
required: true
8+
branch_name:
9+
description: 'Name of the feature branch on the forked repo'
10+
required: true
11+
commit_hash:
12+
description: 'Optional commit hash from the feature branch'
13+
required: false
14+
rustfmt_configs:
15+
description: 'Optional comma separated list of rustfmt config options to pass when running the feature branch'
16+
required: false
17+
18+
jobs:
19+
diff_check:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: checkout
24+
uses: actions/checkout@v3
25+
26+
- name: install rustup
27+
run: |
28+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
29+
sh rustup-init.sh -y --default-toolchain none
30+
rustup target add x86_64-unknown-linux-gnu
31+
32+
- name: check diff
33+
run: bash ${GITHUB_WORKSPACE}/ci/check_diff.sh ${{ github.event.inputs.clone_url }} ${{ github.event.inputs.branch_name }} ${{ github.event.inputs.commit_hash }} ${{ github.event.inputs.rustfmt_configs }}

src/tools/rustfmt/.github/workflows/integration.yml

-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ jobs:
2727
tempdir,
2828
futures-rs,
2929
rust-clippy,
30-
failure,
3130
]
3231
include:
3332
# Allowed Failures
@@ -63,9 +62,6 @@ jobs:
6362
# Original comment was: temporal build failure due to breaking changes in the nightly compiler
6463
- integration: rust-semverver
6564
allow-failure: true
66-
# Can be moved back to include section after https://github.com/rust-lang-nursery/failure/pull/298 is merged
67-
- integration: failure
68-
allow-failure: true
6965

7066
steps:
7167
- name: checkout

src/tools/rustfmt/CHANGELOG.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
## [Unreleased]
44

5+
## [1.5.2] 2023-01-24
6+
7+
### Fixed
8+
9+
- Resolve issue when comments are found within const generic defaults in unit structs [#5668](https://github.com/rust-lang/rustfmt/issues/5668)
10+
- Resolve issue when block comments are found within trait generics [#5358](https://github.com/rust-lang/rustfmt/issues/5358)
11+
- Correctly handle alignment of comments containing unicode characters [#5504](https://github.com/rust-lang/rustfmt/issues/5504)
12+
- Properly indent a single generic bound that requires being written across multiple lines [#4689](https://github.com/rust-lang/rustfmt/issues/4689) (n.b. this change is version gated and will only appear when the `version` configuration option is set to `Two`)
13+
14+
### Changed
15+
16+
- Renamed `fn_args_layout` configuration option to `fn_params_layout` [#4149](https://github.com/rust-lang/rustfmt/issues/4149). Note that `fn_args_layout` has only been soft deprecated: `fn_args_layout` will continue to work without issue, but rustfmt will display a warning to encourage users to switch to the new name
17+
18+
### Added
19+
20+
- 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)
21+
22+
### Misc
23+
24+
- rustfmt now internally supports the ability to have both stable and unstable variants of a configuration option [#5378](https://github.com/rust-lang/rustfmt/issues/5378). This ability will allow the rustfmt team to make certain configuration options available on stable toolchains more quickly because we no longer have to wait for _every_ variant to be stable-ready before stabilizing _any_ variant.
25+
26+
### Install/Download Options
27+
- **rustup (nightly)** - nightly-2023-01-24
28+
- **GitHub Release Binaries** - [Release v1.5.2](https://github.com/rust-lang/rustfmt/releases/tag/v1.5.2)
29+
- **Build from source** - [Tag v1.5.2](https://github.com/rust-lang/rustfmt/tree/v1.5.2), see instructions for how to [install rustfmt from source][install-from-source]
30+
531
## [1.5.1] 2022-06-24
632

733
**N.B** A bug was introduced in v1.5.0/nightly-2022-06-15 which modified formatting. If you happened to run rustfmt over your code with one of those ~10 nightlies it's possible you may have seen formatting changes, and you may see additional changes after this fix since that bug has now been reverted.
@@ -840,7 +866,7 @@ from formatting an attribute #3665
840866
- Fix formatting of raw string literals #2983
841867
- Handle chain with try operators with spaces #2986
842868
- Use correct shape in Visual tuple rewriting #2987
843-
- Impove formatting of arguments with `visual_style = "Visual"` option #2988
869+
- Improve formatting of arguments with `visual_style = "Visual"` option #2988
844870
- Change `print_diff` to output the correct line number 992b179
845871
- Propagate errors about failing to rewrite a macro 6f318e3
846872
- Handle formatting of long function signature #3010

src/tools/rustfmt/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ checksum = "fc71d2faa173b74b232dedc235e3ee1696581bb132fc116fa3626d6151a1a8fb"
476476

477477
[[package]]
478478
name = "rustfmt-config_proc_macro"
479-
version = "0.2.0"
479+
version = "0.3.0"
480480
dependencies = [
481481
"proc-macro2",
482482
"quote",
@@ -485,7 +485,7 @@ dependencies = [
485485

486486
[[package]]
487487
name = "rustfmt-nightly"
488-
version = "1.5.1"
488+
version = "1.5.2"
489489
dependencies = [
490490
"annotate-snippets",
491491
"anyhow",

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.5.1"
4+
version = "1.5.2"
55
description = "Tool to find and fix Rust formatting issues"
66
repository = "https://github.com/rust-lang/rustfmt"
77
readme = "README.md"
@@ -57,7 +57,7 @@ unicode-segmentation = "1.9"
5757
unicode-width = "0.1"
5858
unicode_categories = "0.1"
5959

60-
rustfmt-config_proc_macro = { version = "0.2", path = "config_proc_macro" }
60+
rustfmt-config_proc_macro = { version = "0.3", path = "config_proc_macro" }
6161

6262
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
6363
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`

src/tools/rustfmt/Configurations.md

+179-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Configuring Rustfmt
22

3-
Rustfmt is designed to be very configurable. You can create a TOML file called `rustfmt.toml` or `.rustfmt.toml`, place it in the project or any other parent directory and it will apply the options in that file. If none of these directories contain such a file, both your home directory and a directory called `rustfmt` in your [global config directory](https://docs.rs/dirs/1.0.4/dirs/fn.config_dir.html) (e.g. `.config/rustfmt/`) are checked as well.
3+
Rustfmt is designed to be very configurable. You can create a TOML file called `rustfmt.toml` or `.rustfmt.toml`, place it in the project or any other parent directory and it will apply the options in that file. If none of these directories contain such a file, both your home directory and a directory called `rustfmt` in your [global config directory](https://docs.rs/dirs/4.0.0/dirs/fn.config_dir.html) (e.g. `.config/rustfmt/`) are checked as well.
44

55
A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:
66

@@ -425,7 +425,7 @@ fn example() {
425425

426426
## `comment_width`
427427

428-
Maximum length of comments. No effect unless`wrap_comments = true`.
428+
Maximum length of comments. No effect unless `wrap_comments = true`.
429429

430430
- **Default value**: `80`
431431
- **Possible values**: any positive integer
@@ -589,7 +589,7 @@ doesn't get ignored when aligning.
589589
#### `0` (default):
590590

591591
```rust
592-
enum Bar {
592+
enum Foo {
593593
A = 0,
594594
Bb = 1,
595595
RandomLongVariantGoesHere = 10,
@@ -645,7 +645,8 @@ trailing whitespaces.
645645

646646
## `fn_args_layout`
647647

648-
Control the layout of arguments in a function
648+
This option is deprecated and has been renamed to `fn_params_layout` to better communicate that
649+
it affects the layout of parameters in function signatures.
649650

650651
- **Default value**: `"Tall"`
651652
- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
@@ -753,6 +754,8 @@ trait Lorem {
753754
}
754755
```
755756

757+
See also [`fn_params_layout`](#fn_params_layout)
758+
756759
## `fn_call_width`
757760

758761
Maximum width of the args of a function call before falling back to vertical formatting.
@@ -765,6 +768,117 @@ By default this option is set as a percentage of [`max_width`](#max_width) provi
765768

766769
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
767770

771+
## `fn_params_layout`
772+
773+
Control the layout of parameters in function signatures.
774+
775+
- **Default value**: `"Tall"`
776+
- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
777+
- **Stable**: Yes
778+
779+
#### `"Tall"` (default):
780+
781+
```rust
782+
trait Lorem {
783+
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
784+
785+
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
786+
// body
787+
}
788+
789+
fn lorem(
790+
ipsum: Ipsum,
791+
dolor: Dolor,
792+
sit: Sit,
793+
amet: Amet,
794+
consectetur: Consectetur,
795+
adipiscing: Adipiscing,
796+
elit: Elit,
797+
);
798+
799+
fn lorem(
800+
ipsum: Ipsum,
801+
dolor: Dolor,
802+
sit: Sit,
803+
amet: Amet,
804+
consectetur: Consectetur,
805+
adipiscing: Adipiscing,
806+
elit: Elit,
807+
) {
808+
// body
809+
}
810+
}
811+
```
812+
813+
#### `"Compressed"`:
814+
815+
```rust
816+
trait Lorem {
817+
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
818+
819+
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
820+
// body
821+
}
822+
823+
fn lorem(
824+
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
825+
adipiscing: Adipiscing, elit: Elit,
826+
);
827+
828+
fn lorem(
829+
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
830+
adipiscing: Adipiscing, elit: Elit,
831+
) {
832+
// body
833+
}
834+
}
835+
```
836+
837+
#### `"Vertical"`:
838+
839+
```rust
840+
trait Lorem {
841+
fn lorem(
842+
ipsum: Ipsum,
843+
dolor: Dolor,
844+
sit: Sit,
845+
amet: Amet,
846+
);
847+
848+
fn lorem(
849+
ipsum: Ipsum,
850+
dolor: Dolor,
851+
sit: Sit,
852+
amet: Amet,
853+
) {
854+
// body
855+
}
856+
857+
fn lorem(
858+
ipsum: Ipsum,
859+
dolor: Dolor,
860+
sit: Sit,
861+
amet: Amet,
862+
consectetur: Consectetur,
863+
adipiscing: Adipiscing,
864+
elit: Elit,
865+
);
866+
867+
fn lorem(
868+
ipsum: Ipsum,
869+
dolor: Dolor,
870+
sit: Sit,
871+
amet: Amet,
872+
consectetur: Consectetur,
873+
adipiscing: Adipiscing,
874+
elit: Elit,
875+
) {
876+
// body
877+
}
878+
}
879+
```
880+
881+
768882
## `fn_single_line`
769883

770884
Put single-expression functions on a single line
@@ -1014,6 +1128,62 @@ macro_rules! foo {
10141128

10151129
See also [`format_macro_matchers`](#format_macro_matchers).
10161130

1131+
## `skip_macro_invocations`
1132+
1133+
Skip formatting the bodies of macro invocations with the following names.
1134+
1135+
rustfmt will not format any macro invocation for macros with names set in this list.
1136+
Including the special value "*" will prevent any macro invocations from being formatted.
1137+
1138+
Note: This option does not have any impact on how rustfmt formats macro definitions.
1139+
1140+
- **Default value**: `[]`
1141+
- **Possible values**: a list of macro name idents, `["name_0", "name_1", ..., "*"]`
1142+
- **Stable**: No (tracking issue: [#5346](https://github.com/rust-lang/rustfmt/issues/5346))
1143+
1144+
#### `[]` (default):
1145+
1146+
rustfmt will follow its standard approach to formatting macro invocations.
1147+
1148+
No macro invocations will be skipped based on their name. More information about rustfmt's standard macro invocation formatting behavior can be found in [#5437](https://github.com/rust-lang/rustfmt/discussions/5437).
1149+
1150+
```rust
1151+
lorem!(
1152+
const _: u8 = 0;
1153+
);
1154+
1155+
ipsum!(
1156+
const _: u8 = 0;
1157+
);
1158+
```
1159+
1160+
#### `["lorem"]`:
1161+
1162+
The named macro invocations will be skipped.
1163+
1164+
```rust
1165+
lorem!(
1166+
const _: u8 = 0;
1167+
);
1168+
1169+
ipsum!(
1170+
const _: u8 = 0;
1171+
);
1172+
```
1173+
1174+
#### `["*"]`:
1175+
1176+
The special selector `*` will skip all macro invocations.
1177+
1178+
```rust
1179+
lorem!(
1180+
const _: u8 = 0;
1181+
);
1182+
1183+
ipsum!(
1184+
const _: u8 = 0;
1185+
);
1186+
```
10171187

10181188
## `format_strings`
10191189

@@ -1687,13 +1857,16 @@ pub enum Foo {}
16871857

16881858
## `imports_granularity`
16891859

1690-
How imports should be grouped into `use` statements. Imports will be merged or split to the configured level of granularity.
1860+
Controls how imports are structured in `use` statements. Imports will be merged or split to the configured level of granularity.
1861+
1862+
Similar to other `import` related configuration options, this option operates within the bounds of user-defined groups of imports. See [`group_imports`](#group_imports) for more information on import groups.
1863+
1864+
Note that rustfmt will not modify the granularity of imports containing comments if doing so could potentially lose or misplace said comments.
16911865

16921866
- **Default value**: `Preserve`
16931867
- **Possible values**: `Preserve`, `Crate`, `Module`, `Item`, `One`
16941868
- **Stable**: No (tracking issue: [#4991](https://github.com/rust-lang/rustfmt/issues/4991))
16951869

1696-
Note that rustfmt will not modify the granularity of imports containing comments if doing so could potentially lose or misplace said comments.
16971870

16981871
#### `Preserve` (default):
16991872

0 commit comments

Comments
 (0)