diff options
| author | bors <bors@rust-lang.org> | 2023-09-27 19:17:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-27 19:17:30 +0000 |
| commit | 7b4b1b08b6d4c68a2c7dcb49c312f9fc59d8db86 (patch) | |
| tree | e25f5e7993dba907494945fff16137caacabb4da | |
| parent | d4589a492f5419220c73d216dd538feb30b9b0c5 (diff) | |
| parent | 2ff14b0050145b79769bf207b7d0bee5c98292b8 (diff) | |
| download | rust-7b4b1b08b6d4c68a2c7dcb49c312f9fc59d8db86.tar.gz rust-7b4b1b08b6d4c68a2c7dcb49c312f9fc59d8db86.zip | |
Auto merge of #114901 - compiler-errors:style-guide-wc, r=calebcartwright
Amend style guide section for formatting where clauses in type aliases This PR has two parts: 1. Amend wording about breaking before or after the `=`, which is a style guide bugfix to align it with current rustfmt behavior. 2. Explain how to format trailing (#89122) where clauses, which are preferred in both GATs (#90076) and type aliases (#114662). r? `@joshtriplett`
| -rw-r--r-- | src/doc/style-guide/src/items.md | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md index a6d941f6d04..b215de6ad28 100644 --- a/src/doc/style-guide/src/items.md +++ b/src/doc/style-guide/src/items.md @@ -367,26 +367,52 @@ where ## Type aliases Keep type aliases on one line when they fit. If necessary to break the line, do -so after the `=`, and block-indent the right-hand side: +so before the `=`, and block-indent the right-hand side: ```rust pub type Foo = Bar<T>; // If multi-line is required -type VeryLongType<T, U: SomeBound> = - AnEvenLongerType<T, U, Foo<T>>; +type VeryLongType<T, U: SomeBound> + = AnEvenLongerType<T, U, Foo<T>>; ``` -Where possible avoid `where` clauses and keep type constraints inline. Where -that is not possible split the line before and after the `where` clause (and -split the `where` clause as normal), e.g., +When there is a trailing `where` clause after the type, and no `where` clause +present before the type, break before the `=` and indent. Then break before the +`where` keyword and format the clauses normally, e.g., ```rust +// With only a trailing where clause type VeryLongType<T, U> + = AnEvenLongerType<T, U, Foo<T>> +where + T: U::AnAssociatedType, + U: SomeBound; +``` + +When there is a `where` clause before the type, format it normally, and break +after the last clause. Do not indent before the `=` to leave it visually +distinct from the indented clauses that precede it. If there is additionally a +`where` clause after the type, break before the `where` keyword and format the +clauses normally. + +```rust +// With only a preceding where clause. +type WithPrecedingWC<T, U> where T: U::AnAssociatedType, U: SomeBound, = AnEvenLongerType<T, U, Foo<T>>; + +// Or with both a preceding and trailing where clause. +type WithPrecedingWC<T, U> +where + T: U::AnAssociatedType, + U: SomeBound, += AnEvenLongerType<T, U, Foo<T>> +where + T: U::AnAssociatedType2, + U: SomeBound2; ``` ## Associated types |
