Skip to content

Commit

Permalink
Describe how to format trailing where clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 16, 2023
1 parent 85254c9 commit f707b9c
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/doc/style-guide/src/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f707b9c

Please sign in to comment.