about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2024-01-02 04:59:24 -0800
committerJosh Triplett <josh@joshtriplett.org>2024-05-13 16:42:47 +0200
commit3742a4bd902f5d6efd2b401a6dab5e4087070d5d (patch)
tree854697abc2037d95696e97a917a9820a5a2a03e7
parentabb95639ef2b837dbfe7b5d18f51fadda29711cb (diff)
downloadrust-3742a4bd902f5d6efd2b401a6dab5e4087070d5d.tar.gz
rust-3742a4bd902f5d6efd2b401a6dab5e4087070d5d.zip
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.
-rw-r--r--src/doc/style-guide/src/editions.md1
-rw-r--r--src/doc/style-guide/src/items.md13
2 files changed, 13 insertions, 1 deletions
diff --git a/src/doc/style-guide/src/editions.md b/src/doc/style-guide/src/editions.md
index b9a89c20cee..9d593f80810 100644
--- a/src/doc/style-guide/src/editions.md
+++ b/src/doc/style-guide/src/editions.md
@@ -43,6 +43,7 @@ include:
 - Miscellaneous `rustfmt` bugfixes.
 - Use version-sort (sort `x8`, `x16`, `x32`, `x64`, `x128` in that order).
 - Change "ASCIIbetical" sort to Unicode-aware "non-lowercase before lowercase".
+- Format single associated type `where` clauses on the same line if they fit.
 
 ## Rust 2015/2018/2021 style edition
 
diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md
index 0066a4bacb9..06bac129871 100644
--- a/src/doc/style-guide/src/items.md
+++ b/src/doc/style-guide/src/items.md
@@ -421,9 +421,20 @@ Format associated types like type aliases. Where an associated type has a
 bound, put a space after the colon but not before:
 
 ```rust
-pub type Foo: Bar;
+type Foo: Bar;
 ```
 
+If an associated type has no `=`, and has a `where` clause with only one entry,
+format the entire type declaration including the `where` clause on the same
+line if it fits:
+
+```rust
+type Item<'a> where Self: 'a;
+```
+
+If the associated type has a `=`, or if the `where` clause contains multiple
+entries, format it across multiple lines as with a type alias.
+
 ## extern items
 
 When writing extern items (such as `extern "C" fn`), always specify the ABI.