Skip to content

Commit 71b0551

Browse files
committed
Add information about || and && to Grammar describing while let.
Also fix italics to be consistent with other pages.
1 parent 8e5873c commit 71b0551

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/expressions/loop-expr.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ have type compatible with the value of the `break` expression(s).
4545

4646
> **<sup>Syntax</sup>**\
4747
> _PredicateLoopExpression_ :\
48-
> &nbsp;&nbsp; `while` [_Expression_]<sub>except struct expression</sub> [_BlockExpression_]
48+
> &nbsp;&nbsp; `while` [_Expression_]<sub>_except struct expression_</sub> [_BlockExpression_]
4949
5050
A `while` loop begins by evaluating the boolean loop conditional expression. If
5151
the loop conditional expression evaluates to `true`, the loop body block
@@ -67,7 +67,7 @@ while i < 10 {
6767

6868
> **<sup>Syntax</sup>**\
6969
> [_PredicatePatternLoopExpression_] :\
70-
> &nbsp;&nbsp; `while` `let` [_MatchArmPatterns_] `=` [_Expression_]<sub>except struct expression</sub>
70+
> &nbsp;&nbsp; `while` `let` [_MatchArmPatterns_] `=` [_Expression_]<sub>_except struct or lazy boolean operator expression_</sub>
7171
> [_BlockExpression_]
7272
7373
A `while let` loop is semantically similar to a `while` loop but in place of a
@@ -123,11 +123,32 @@ while let Some(v @ 1) | Some(v @ 2) = vals.pop() {
123123
}
124124
```
125125

126+
The expression cannot be a [lazy boolean operator expression][_LazyBooleanOperatorExpression_].
127+
Use of a lazy boolean operator is ambiguous with a planned feature change
128+
of the language (the implementation of if-let chains - see [eRFC 2947][_eRFCIfLetChain_]).
129+
When lazy boolean operator expression is desired, this can be achieved
130+
by using parenthesis as below:
131+
132+
<!-- ignore: psuedo code -->
133+
```rust,ignore
134+
// Before...
135+
while let PAT = EXPR && EXPR { .. }
136+
137+
// After...
138+
while let PAT = ( EXPR && EXPR ) { .. }
139+
140+
// Before...
141+
while let PAT = EXPR || EXPR { .. }
142+
143+
// After...
144+
while let PAT = ( EXPR || EXPR ) { .. }
145+
```
146+
126147
## Iterator loops
127148

128149
> **<sup>Syntax</sup>**\
129150
> _IteratorLoopExpression_ :\
130-
> &nbsp;&nbsp; `for` [_Pattern_] `in` [_Expression_]<sub>except struct expression</sub>
151+
> &nbsp;&nbsp; `for` [_Pattern_] `in` [_Expression_]<sub>_except struct expression_</sub>
131152
> [_BlockExpression_]
132153
133154
A `for` expression is a syntactic construct for looping over elements provided

0 commit comments

Comments
 (0)