From 9ff777bf50cb26107496c1bfdd178c56c5a57cca Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 10 Jan 2024 19:21:27 -0800 Subject: [PATCH] style-guide: Also format where clauses on one line for short function decls --- src/doc/style-guide/src/items.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md index 095e5512ea9..9b8cdaed88b 100644 --- a/src/doc/style-guide/src/items.md +++ b/src/doc/style-guide/src/items.md @@ -295,8 +295,18 @@ Prefer to use single-letter names for generic parameters. These rules apply for `where` clauses on any item. -If immediately following a closing bracket of any kind, write the keyword -`where` on the same line, with a space before it. +If a where clause is short, and appears on a short one-line function +declaration with no body or a short associated type with no `=`, format it on +the same line as the declaration: + +```rust +fn new(&self) -> Self where Self: Sized; + +type Item<'a>: SomeTrait where Self: 'a; +``` + +Otherwise, if immediately following a closing bracket of any kind, write the +keyword `where` on the same line, with a space before it. Otherwise, put `where` on a new line at the same indentation level. Put each 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: 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: +If an associated type is short, 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;