diff options
| author | Michael Goulet <michael@errs.io> | 2023-08-16 16:41:49 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-08-16 16:45:57 +0000 |
| commit | f707b9cd707d84768687caa025d483cef61ed440 (patch) | |
| tree | 6d04b7f04bc3edfb6b1bc18cee20171f2223e835 | |
| parent | 85254c9dd8266f24658071b773fbc3ba2da7b35c (diff) | |
| download | rust-f707b9cd707d84768687caa025d483cef61ed440.tar.gz rust-f707b9cd707d84768687caa025d483cef61ed440.zip | |
Describe how to format trailing where clauses
| -rw-r--r-- | src/doc/style-guide/src/items.md | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md index b93f2fbde4d..dc10f4ff15d 100644 --- a/src/doc/style-guide/src/items.md +++ b/src/doc/style-guide/src/items.md @@ -378,15 +378,38 @@ type VeryLongType<T, U: SomeBound> ``` 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., +that is not possible, prefer a trailing `where` clause over one that precedes +the type. Split the line before and after a trailing `where` clause (and split +the `where` clause as normal) and indent before the `=` and type, e.g., ```rust 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. + +``` +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 |
