@@ -54,17 +54,26 @@ fn outer() {
54
54
> ** <sup >Syntax</sup >** \
55
55
> _ LetStatement_ :\
56
56
>   ;  ; [ _ OuterAttribute_ ] <sup >\* </sup > ` let ` [ _ PatternNoTopAlt_ ]
57
- > ( ` : ` [ _ Type_ ] )<sup >?</sup > (` = ` [ _ Expression_ ] )<sup >?</sup > ` ; `
57
+ > ( ` : ` [ _ Type_ ] )<sup >?</sup > (` = ` [ _ Expression_ ]
58
+ > ( ` else ` [ _ BlockExpression_ ] ) <sup >?</sup > ) <sup >?</sup > ` ; `
58
59
59
- A * ` let ` statement* introduces a new set of [ variables] , given by an
60
- irrefutable [ pattern ] . The pattern is followed optionally by a type
61
- annotation and then optionally by an initializer expression. When no
62
- type annotation is given, the compiler will infer the type, or signal
60
+ A * ` let ` statement* introduces a new set of [ variables] , given by a [ pattern ] .
61
+ The pattern is followed optionally by a type annotation and then either ends,
62
+ or is followed by an initializer expression plus an optional ` else ` block.
63
+ When no type annotation is given, the compiler will infer the type, or signal
63
64
an error if insufficient type information is available for definite
64
65
inference. Any variables introduced by a variable declaration are visible
65
66
from the point of declaration until the end of the enclosing block scope,
66
67
except when they are shadowed by another variable declaration.
67
68
69
+ If an ` else ` block is not present, the pattern must be irrefutable.
70
+ If an ` else ` block is present, the pattern may be refutable.
71
+ If the pattern does not match (this requires it to be refutable), the ` else `
72
+ block is executed.
73
+ The ` else ` block must always diverge (evaluate to the [ never type] ).
74
+ If an ` else ` block is present, restrictions apply on the expression:
75
+ It must not be a [ _ LazyBooleanExpression_ ] , or end in a ` } ` token.
76
+
68
77
## Expression statements
69
78
70
79
> ** <sup >Syntax</sup >** \
@@ -121,16 +130,19 @@ statement are [`cfg`], and [the lint check attributes].
121
130
[ function ] : items/functions.md
122
131
[ item ] : items.md
123
132
[ module ] : items/modules.md
133
+ [ never type ] : types/never.md
124
134
[ canonical path ] : paths.md#canonical-paths
125
135
[ implementations ] : items/implementations.md
126
136
[ variables ] : variables.md
127
137
[ outer attributes ] : attributes.md
128
138
[ `cfg` ] : conditional-compilation.md
129
139
[ the lint check attributes ] : attributes/diagnostics.md#lint-check-attributes
130
140
[ pattern ] : patterns.md
141
+ [ _BlockExpression_ ] : expressions/block-expr.md
131
142
[ _ExpressionStatement_ ] : #expression-statements
132
143
[ _Expression_ ] : expressions.md
133
144
[ _Item_ ] : items.md
145
+ [ _LazyBooleanExpression_ ] : expressions/operator-expr.md#lazy-boolean-operators
134
146
[ _LetStatement_ ] : #let-statements
135
147
[ _MacroInvocationSemi_ ] : macros.md#macro-invocation
136
148
[ _OuterAttribute_ ] : attributes.md
0 commit comments