Skip to content

Commit 9214ce6

Browse files
authored
Merge pull request rust-lang#437 from davidtwco/erfc-2947-documentation
Mention syntax ambiguity for eRFC 2947.
2 parents 38a98e0 + 9f758ac commit 9214ce6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Diff for: src/expressions/if-expr.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ assert_eq!(y, "Bigger");
4444

4545
> **<sup>Syntax</sup>**\
4646
> _IfLetExpression_ :\
47-
> &nbsp;&nbsp; `if` `let` [_Pattern_] `=` [_Expression_]<sub>_except struct expression_</sub>
47+
> &nbsp;&nbsp; `if` `let` [_Pattern_] `=` [_Expression_]<sub>_except struct or lazy boolean operator expression_</sub>
4848
> [_BlockExpression_]\
4949
> &nbsp;&nbsp; (`else` (
5050
> [_BlockExpression_]
@@ -111,6 +111,28 @@ match EXPR {
111111
}
112112
```
113113

114+
The expression cannot be a [lazy boolean operator expression][_LazyBooleanOperatorExpression_].
115+
Use of a lazy boolean operator is ambiguous with a planned feature change
116+
of the language (the implementation of if-let chains - see [eRFC 2947][_eRFCIfLetChain_]).
117+
When lazy boolean operator expression is desired, this can be achieved
118+
by using parenthesis as below:
119+
120+
```rust,ignore
121+
// Before...
122+
if let PAT = EXPR && EXPR { .. }
123+
124+
// After...
125+
if let PAT = ( EXPR && EXPR ) { .. }
126+
127+
// Before...
128+
if let PAT = EXPR || EXPR { .. }
129+
130+
// After...
131+
if let PAT = ( EXPR || EXPR ) { .. }
132+
```
133+
114134
[_Expression_]: expressions.html
115135
[_BlockExpression_]: expressions/block-expr.html
116136
[_Pattern_]: patterns.html
137+
[_LazyBooleanOperatorExpression_]: expressions/operator-expr.html#lazy-boolean-operators
138+
[_eRFCIfLetChain_]: https://github.com/rust-lang/rfcs/blob/master/text/2497-if-let-chains.md#rollout-plan-and-transitioning-to-rust-2018

0 commit comments

Comments
 (0)