Skip to content

Commit 6324736

Browse files
committed
style-guide: Also format where clauses on one line for short function decls
1 parent f49d9ca commit 6324736

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

+15-5
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,18 @@ Prefer to use single-letter names for generic parameters.
295295

296296
These rules apply for `where` clauses on any item.
297297

298-
If immediately following a closing bracket of any kind, write the keyword
299-
`where` on the same line, with a space before it.
298+
If a where clause is short, and appears on a short one-line function
299+
declaration with no body or a short associated type with no `=`, format it on
300+
the same line as the declaration:
301+
302+
```rust
303+
fn new(&self) -> Self where Self: Sized;
304+
305+
type Item<'a>: SomeTrait where Self: 'a;
306+
```
307+
308+
Otherwise, if immediately following a closing bracket of any kind, write the
309+
keyword `where` on the same line, with a space before it.
300310

301311
Otherwise, put `where` on a new line at the same indentation level. Put each
302312
component of a `where` clause on its own line, block-indented. Use a trailing
@@ -424,9 +434,9 @@ bound, put a space after the colon but not before:
424434
type Foo: Bar;
425435
```
426436

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:
437+
If an associated type is short, has no `=`, and has a `where` clause with only
438+
one entry, format the entire type declaration including the `where` clause on
439+
the same line if it fits:
430440

431441
```rust
432442
type Item<'a> where Self: 'a;

0 commit comments

Comments
 (0)