Skip to content

Commit

Permalink
Merge branch 'rust-lang:master' into handling-numbered-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
anforowicz authored Aug 26, 2022
2 parents 332a16d + 38659ec commit e88c3d1
Show file tree
Hide file tree
Showing 98 changed files with 2,358 additions and 162 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/check_diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Diff Check
on:
workflow_dispatch:
inputs:
clone_url:
description: 'Git url of a rustfmt fork to compare against the latest master rustfmt'
required: true
branch_name:
description: 'Name of the feature branch on the forked repo'
required: true
commit_hash:
description: 'Optional commit hash from the feature branch'
required: false
rustfmt_configs:
description: 'Optional comma separated list of rustfmt config options to pass when running the feature branch'
required: false

jobs:
diff_check:
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v3

- name: install rustup
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
sh rustup-init.sh -y --default-toolchain none
rustup target add x86_64-unknown-linux-gnu
- name: check diff
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 }}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ from formatting an attribute #3665
- Fix formatting of raw string literals #2983
- Handle chain with try operators with spaces #2986
- Use correct shape in Visual tuple rewriting #2987
- Impove formatting of arguments with `visual_style = "Visual"` option #2988
- Improve formatting of arguments with `visual_style = "Visual"` option #2988
- Change `print_diff` to output the correct line number 992b179
- Propagate errors about failing to rewrite a macro 6f318e3
- Handle formatting of long function signature #3010
Expand Down
176 changes: 173 additions & 3 deletions Configurations.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configuring Rustfmt

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

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

Expand Down Expand Up @@ -589,7 +589,7 @@ doesn't get ignored when aligning.
#### `0` (default):

```rust
enum Bar {
enum Foo {
A = 0,
Bb = 1,
RandomLongVariantGoesHere = 10,
Expand Down Expand Up @@ -645,7 +645,8 @@ trailing whitespaces.

## `fn_args_layout`

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

- **Default value**: `"Tall"`
- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
Expand Down Expand Up @@ -753,6 +754,8 @@ trait Lorem {
}
```

See also [`fn_params_layout`](#fn_params_layout)

## `fn_call_width`

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

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

## `fn_params_layout`

Control the layout of parameters in function signatures.

- **Default value**: `"Tall"`
- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
- **Stable**: Yes

#### `"Tall"` (default):

```rust
trait Lorem {
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);

fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
// body
}

fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
);

fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
) {
// body
}
}
```

#### `"Compressed"`:

```rust
trait Lorem {
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);

fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
// body
}

fn lorem(
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
adipiscing: Adipiscing, elit: Elit,
);

fn lorem(
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
adipiscing: Adipiscing, elit: Elit,
) {
// body
}
}
```

#### `"Vertical"`:

```rust
trait Lorem {
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
);

fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
) {
// body
}

fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
);

fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
) {
// body
}
}
```


## `fn_single_line`

Put single-expression functions on a single line
Expand Down Expand Up @@ -1014,6 +1128,62 @@ macro_rules! foo {

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

## `skip_macro_invocations`

Skip formatting the bodies of macro invocations with the following names.

rustfmt will not format any macro invocation for macros with names set in this list.
Including the special value "*" will prevent any macro invocations from being formatted.

Note: This option does not have any impact on how rustfmt formats macro definitions.

- **Default value**: `[]`
- **Possible values**: a list of macro name idents, `["name_0", "name_1", ..., "*"]`
- **Stable**: No (tracking issue: [#5346](https://github.com/rust-lang/rustfmt/issues/5346))

#### `[]` (default):

rustfmt will follow its standard approach to formatting macro invocations.

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

```rust
lorem!(
const _: u8 = 0;
);

ipsum!(
const _: u8 = 0;
);
```

#### `["lorem"]`:

The named macro invocations will be skipped.

```rust
lorem!(
const _: u8 = 0;
);

ipsum!(
const _: u8 = 0;
);
```

#### `["*"]`:

The special selector `*` will skip all macro invocations.

```rust
lorem!(
const _: u8 = 0;
);

ipsum!(
const _: u8 = 0;
);
```

## `format_strings`

Expand Down
2 changes: 1 addition & 1 deletion Processes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ This document outlines processes regarding management of rustfmt.

# Stabilising an Option

In this Section, we describe how to stabilise an option of the rustfmt's configration.
In this Section, we describe how to stabilise an option of the rustfmt's configuration.

## Conditions

Expand Down
Loading

0 comments on commit e88c3d1

Please sign in to comment.