5 Put a space after the `:` and on both sides of the `=` (if they are present).
6 Don't put a space before the semicolon.
10 let pattern: Type = expr;
17 If possible, format the declaration on a single line. If not possible, then try
18 splitting after the `=`, if the declaration fits on two lines. Block-indent the
26 If the first line still does not fit on a single line, split after the `:`, and
27 use block indentation. If the type requires multiple lines, even after
28 line-breaking after the `:`, then place the first line on the same line as the
29 `:`, subject to the [combining rules](expressions.html#combinable-expressions).
52 If the expression covers multiple lines, if the first line of the expression
53 fits in the remaining space, it stays on the same line as the `=`, and the rest
54 of the expression is not further indented. If the first line does not fit, then
55 put the expression on subsequent lines, block indented. If the expression is a
56 block and the type or pattern cover multiple lines, put the opening brace on a
57 new line and not indented (this provides separation for the interior of the
58 block from the type); otherwise, the opening brace follows the `=`.
103 ### else blocks (let-else statements)
105 A let statement can contain an `else` component, making it a let-else statement.
106 In this case, always apply the same formatting rules to the components preceding
107 the `else` block (i.e. the `let pattern: Type = initializer_expr` portion)
108 as described [for other let statements](#let-statements).
110 Format the entire let-else statement on a single line if all the following are
113 * the entire statement is *short*
114 * the `else` block contains only a single-line expression and no statements
115 * the `else` block contains no comments
116 * the let statement components preceding the `else` block can be formatted on a single line
119 let Some(1) = opt else { return };
122 Otherwise, the let-else statement requires some line breaks.
124 If breaking a let-else statement across multiple lines, never break between the
125 `else` and the `{`, and always break before the `}`.
127 If the let statement components preceding the `else` can be formatted on a
128 single line, but the let-else does not qualify to be placed entirely on a
129 single line, put the `else {` on the same line as the initializer expression,
130 with a space between them, then break the line after the `{`. Indent the
131 closing `}` to match the `let`, and indent the contained block one step
135 let Some(1) = opt else {
139 let Some(1) = opt else {
145 If the let statement components preceding the `else` can be formatted on a
146 single line, but the `else {` does not fit on the same line, break the line
150 let Some(x) = some_really_really_really_really_really_really_really_really_really_long_name
156 If the initializer expression is multi-line, put the `else` keyword and opening
157 brace of the block (i.e. `else {`) on the same line as the end of the
158 initializer expression, with a space between them, if and only if all the
161 * The initializer expression ends with one or more closing
162 parentheses, square brackets, and/or braces
163 * There is nothing else on that line
164 * That line has the same indentation level as the initial `let` keyword.
171 fairly_long_identifier,
181 Otherwise, put the `else` keyword and opening brace on the next line after the
182 end of the initializer expression, with the `else` keyword at the same
183 indentation level as the `let` keyword.
189 let Some(x) = abcdef()
192 some_really_really_really_long_ident,
198 .qux("fffffffffffffffff")
203 let Some(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =
204 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
209 let LongStructName(AnotherStruct {
218 let LongStructName(AnotherStruct {
222 }) = multi_line_function_call(
233 ## Macros in statement position
235 For a macro use in statement position, use parentheses or square brackets as
236 delimiters, and terminate it with a semicolon. Do not put spaces around the
237 name, `!`, the delimiters, or the `;`.
244 ## Expressions in statement position
246 Do not put space between the expression and the semicolon.
252 Terminate all expressions in statement position with a semicolon, unless they
253 end with a block or are used as the value for a block.
270 Use a semicolon where an expression has void type, even if it could be