Skip to content

Commit 3742a4b

Browse files
committed
style-guide: Format single associated type where clauses on the same line
In particular, lifetime-generic associated types often have a `where Self: 'a` bound, which we can format on the same line.
1 parent abb9563 commit 3742a4b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/doc/style-guide/src/editions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ include:
4343
- Miscellaneous `rustfmt` bugfixes.
4444
- Use version-sort (sort `x8`, `x16`, `x32`, `x64`, `x128` in that order).
4545
- Change "ASCIIbetical" sort to Unicode-aware "non-lowercase before lowercase".
46+
- Format single associated type `where` clauses on the same line if they fit.
4647

4748
## Rust 2015/2018/2021 style edition
4849

src/doc/style-guide/src/items.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,20 @@ Format associated types like type aliases. Where an associated type has a
421421
bound, put a space after the colon but not before:
422422

423423
```rust
424-
pub type Foo: Bar;
424+
type Foo: Bar;
425425
```
426426

427+
If an associated type has no `=`, and has a `where` clause with only one entry,
428+
format the entire type declaration including the `where` clause on the same
429+
line if it fits:
430+
431+
```rust
432+
type Item<'a> where Self: 'a;
433+
```
434+
435+
If the associated type has a `=`, or if the `where` clause contains multiple
436+
entries, format it across multiple lines as with a type alias.
437+
427438
## extern items
428439

429440
When writing extern items (such as `extern "C" fn`), always specify the ABI.

0 commit comments

Comments
 (0)