1- ## Expressions
1+ # Expressions
22
3- ### Blocks
3+ ## Blocks
44
55A block expression must have a newline after the initial ` { ` and before the
66terminal ` } ` , unless it qualifies to be written as a single line based on
@@ -116,8 +116,7 @@ fn main() {
116116}
117117```
118118
119-
120- ### Closures
119+ ## Closures
121120
122121Don't put any extra spaces before the first ` | ` (unless the closure is prefixed
123122by a keyword such as ` move ` ); put a space between the second ` | ` and the
@@ -155,8 +154,7 @@ move |arg1: i32, arg2: i32| -> i32 {
155154}
156155```
157156
158-
159- ### Struct literals
157+ ## Struct literals
160158
161159If a struct literal is * small* , format it on a single line, and do not use a
162160trailing comma. If not, split it across multiple lines, with each field on its
@@ -185,8 +183,7 @@ let f = Foo {
185183};
186184```
187185
188-
189- ### Tuple literals
186+ ## Tuple literals
190187
191188Use a single-line form where possible. Do not put spaces between the opening
192189parenthesis and the first element, or between the last element and the closing
@@ -205,8 +202,7 @@ let x = (
205202);
206203```
207204
208-
209- ### Tuple struct literals
205+ ## Tuple struct literals
210206
211207Do not put space between the identifier and the opening parenthesis. Otherwise,
212208follow the rules for tuple literals:
@@ -220,8 +216,7 @@ let x = Foo(
220216);
221217```
222218
223-
224- ### Enum literals
219+ ## Enum literals
225220
226221Follow the formatting rules for the various struct literals. Prefer using the
227222name of the enum as a qualifying name, unless the enum is in the prelude:
@@ -235,8 +230,7 @@ Foo::Baz {
235230Ok (an_expr )
236231```
237232
238-
239- ### Array literals
233+ ## Array literals
240234
241235Write small array literals on a single line. Do not put spaces between the opening
242236square bracket and the first element, or between the last element and the closing
@@ -276,8 +270,7 @@ fn main() {
276270}
277271```
278272
279-
280- ### Array accesses, indexing, and slicing.
273+ ## Array accesses, indexing, and slicing
281274
282275Don't put spaces around the square brackets. Avoid breaking lines if possible.
283276Never break a line between the target expression and the opening square
@@ -300,13 +293,13 @@ fn main() {
300293}
301294```
302295
303- ### Unary operations
296+ ## Unary operations
304297
305298Do not include a space between a unary op and its operand (i.e., ` !x ` , not
306299` ! x ` ). However, there must be a space after ` &mut ` . Avoid line-breaking
307300between a unary operator and its operand.
308301
309- ### Binary operations
302+ ## Binary operations
310303
311304Do include spaces around binary ops (i.e., ` x + 1 ` , not ` x+1 ` ) (including ` = `
312305and other assignment operators such as ` += ` or ` *= ` ).
@@ -335,7 +328,7 @@ foo_bar
335328Prefer line-breaking at an assignment operator (either ` = ` or ` += ` , etc.) rather
336329than at other binary operators.
337330
338- ### Control flow
331+ ## Control flow
339332
340333Do not include extraneous parentheses for ` if ` and ` while ` expressions.
341334
@@ -354,7 +347,7 @@ if (true) {
354347Do include extraneous parentheses if it makes an arithmetic or logic expression
355348easier to understand (` (x * 15) + (y * 20) ` is fine)
356349
357- ### Function calls
350+ ## Function calls
358351
359352Do not put a space between the function name, and the opening parenthesis.
360353
@@ -364,7 +357,7 @@ Do put a space between an argument, and the comma which precedes it.
364357
365358Prefer not to break a line in the callee expression.
366359
367- #### Single-line calls
360+ ### Single-line calls
368361
369362Do not put a space between the function name and open paren, between the open
370363paren and the first argument, or between the last argument and the close paren.
@@ -375,7 +368,7 @@ Do not put a comma after the last argument.
375368foo (x , y , z )
376369```
377370
378- #### Multi-line calls
371+ ### Multi-line calls
379372
380373If the function call is not * small* , it would otherwise over-run the max width,
381374or any argument or the callee is multi-line, then format the call across
@@ -390,8 +383,7 @@ a_function_call(
390383)
391384```
392385
393-
394- ### Method calls
386+ ## Method calls
395387
396388Follow the function rules for calling.
397389
@@ -401,15 +393,14 @@ Do not put any spaces around the `.`.
401393x . foo (). bar (). baz (x , y , z );
402394```
403395
404-
405- ### Macro uses
396+ ## Macro uses
406397
407398If a macro can be parsed like other constructs, format it like those
408399constructs. For example, a macro use ` foo!(a, b, c) ` can be parsed like a
409400function call (ignoring the ` ! ` ), so format it using the rules for function
410401calls.
411402
412- #### Special case macros
403+ ### Special case macros
413404
414405For macros which take a format string, if all other arguments are * small* ,
415406format the arguments before the format string on a single line if they fit, and
@@ -430,17 +421,15 @@ assert_eq!(
430421);
431422```
432423
433-
434- ### Casts (` as ` )
424+ ## Casts (` as ` )
435425
436426Put spaces before and after ` as ` :
437427
438428``` rust
439429let cstr = " Hi\ 0" as * const str as * const [u8 ] as * const std :: os :: raw :: c_char ;
440430```
441431
442-
443- ### Chains of fields and method calls
432+ ## Chains of fields and method calls
444433
445434A chain is a sequence of field accesses, method calls, and/or uses of the try
446435operator ` ? ` . E.g., ` a.b.c().d ` or ` foo?.bar().baz? ` .
478467 . qux ();
479468```
480469
481- #### Multi-line elements
470+ ### Multi-line elements
482471
483472If any element in a chain is formatted across multiple lines, put that element
484473and any later elements on their own lines.
@@ -513,7 +502,7 @@ self.pre_comment.as_ref().map_or(
513502)
514503```
515504
516- ### Control flow expressions
505+ ## Control flow expressions
517506
518507This section covers ` if ` , ` if let ` , ` loop ` , ` while ` , ` while let ` , and ` for `
519508expressions.
@@ -584,8 +573,7 @@ if !self.config.file_lines().intersects(
584573}
585574```
586575
587-
588- #### Single line ` if else `
576+ ### Single line ` if else `
589577
590578Put an ` if else ` or ` if let else ` on a single line if it occurs in expression
591579context (i.e., is not a standalone statement), it contains a single ` else `
@@ -608,8 +596,7 @@ if x {
608596}
609597```
610598
611-
612- ### Match
599+ ## Match
613600
614601Prefer not to line-break inside the discriminant expression. Always break after
615602the opening brace and before the closing brace. Block-indent the match arms
@@ -718,7 +705,7 @@ match foo {
718705}
719706```
720707
721- #### Line-breaking
708+ ### Line-breaking
722709
723710If using a block form on the right-hand side of a match arm makes it possible
724711to avoid breaking on the left-hand side, do that:
@@ -812,8 +799,7 @@ small_no_tuple:
812799
813800E.g., ` &&Some(foo) ` matches, ` Foo(4, Bar) ` does not.
814801
815-
816- ### Combinable expressions
802+ ## Combinable expressions
817803
818804Where a function call has a single argument, and that argument is formatted
819805across multiple-lines, format the outer call as if it were a single-line call,
@@ -861,8 +847,7 @@ foo(first_arg, x, |param| {
861847})
862848```
863849
864-
865- ### Ranges
850+ ## Ranges
866851
867852Do not put spaces in ranges, e.g., ` 0..10 ` , ` x..=y ` , ` ..x.len() ` , ` foo.. ` .
868853
@@ -879,8 +864,7 @@ For the sake of indicating precedence, if either bound is a compound
879864expression, use parentheses around it, e.g., ` ..(x + 1) ` , ` (x.f)..(x.f.len()) ` ,
880865or ` 0..(x - 10) ` .
881866
882-
883- ### Hexadecimal literals
867+ ## Hexadecimal literals
884868
885869Hexadecimal literals may use upper- or lower-case letters, but they must not be
886870mixed within the same literal. Projects should use the same case for all
0 commit comments