Skip to content

Commit 5010ff3

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 e51e98d commit 5010ff3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ history of the style guide. Notable changes in the Rust 2024 style edition
3737
include:
3838

3939
- Miscellaneous `rustfmt` bugfixes.
40+
- Format single associated type `where` clauses on the same line if they fit.
4041

4142
## Rust 2015/2018/2021 style edition
4243

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

+12-1
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 declaration has no bounds, and has a `where` clause with
428+
a single entry, format the entire type declaration including the `where` clause
429+
on the same line if it fits:
430+
431+
```rust
432+
type Item<'a> where Self: 'a;
433+
```
434+
435+
If the `where` clause contains multiple entries, or the associated type has any
436+
bounds, 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)