@@ -110,3 +110,102 @@ Use `{}` for the full definition of the macro.
110
110
macro_rules! foo {
111
111
}
112
112
```
113
+
114
+ ### Generics
115
+
116
+ TODO
117
+
118
+
119
+ ### ` where ` clauses
120
+
121
+ These rules apply for ` where ` clauses on any item.
122
+
123
+ A ` where ` clause may immediately follow a closing bracket of any kind.
124
+ Otherwise, it must start a new line, with no indent. Each component of a ` where `
125
+ clause must be on its own line and be block indented. There should be a trailing
126
+ comma, unless the clause is terminated with a semicolon. If the ` where ` clause
127
+ is followed by a block (or assignment), the block should be started on a new
128
+ line. Examples:
129
+
130
+ ```
131
+ fn function<T, U>(args)
132
+ where
133
+ T: Bound,
134
+ U: AnotherBound,
135
+ {
136
+ body
137
+ }
138
+
139
+ fn foo<T>(
140
+ args
141
+ ) -> ReturnType
142
+ where
143
+ T: Bound,
144
+ {
145
+ body
146
+ }
147
+
148
+ fn foo<T, U>(
149
+ args,
150
+ ) where
151
+ T: Bound,
152
+ U: AnotherBound,
153
+ {
154
+ body
155
+ }
156
+
157
+ fn foo<T, U>(
158
+ args
159
+ ) -> ReturnType
160
+ where
161
+ T: Bound,
162
+ U: AnotherBound; // Note, no trailing comma.
163
+
164
+ type Foo<T>
165
+ where
166
+ T: Bound
167
+ = Bar<T>;
168
+ ```
169
+
170
+ If a ` where ` clause is very short, we recommend using an inline bound on the
171
+ type parameter.
172
+
173
+
174
+ If a component of a ` where ` clause is long, it may be broken before ` + ` and
175
+ further block indented. Each bound should go on its own line. E.g.,
176
+
177
+ ```
178
+ impl<T: ?Sized, Idx> IndexRanges<Idx> for T
179
+ where
180
+ T: Index<Range<Idx>, Output = Self::Output>
181
+ + Index<RangeTo<Idx>, Output = Self::Output>
182
+ + Index<RangeFrom<Idx>, Output = Self::Output>
183
+ + Index<RangeInclusive<Idx>, Output = Self::Output>
184
+ + Index<RangeToInclusive<Idx>, Output = Self::Output> + Index<RangeFull>
185
+ ```
186
+
187
+ #### Option - ` where_single_line `
188
+
189
+ ` where_single_line ` is ` false ` by default. If ` true ` , then a where clause with
190
+ exactly one component may be formatted on a single line if the rest of the
191
+ item's signature is also kept on one line. In this case, there is no need for a
192
+ trailing comma and if followed by a block, no need for a newline before the
193
+ block. E.g.,
194
+
195
+ ```
196
+ // May be single-lined.
197
+ fn foo<T>(args) -> ReturnType
198
+ where T: Bound {
199
+ body
200
+ }
201
+
202
+ // Must be multi-lined.
203
+ fn foo<T>(
204
+ args
205
+ ) -> ReturnType
206
+ where
207
+ T: Bound,
208
+ {
209
+ body
210
+ }
211
+ ```
0 commit comments