Skip to content

Commit

Permalink
Add let_chains references
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Mar 16, 2022
1 parent 0a2fe66 commit 514d8b3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/expressions/if-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@

> **<sup>Syntax</sup>**\
> _IfExpression_ :\
> &nbsp;&nbsp; `if` [_Expression_]<sub>_except struct expression_</sub> [_BlockExpression_]\
> &nbsp;&nbsp; (`else` (
> &nbsp;&nbsp; `if` _inIfList_ [_BlockExpression_]\
> &nbsp;&nbsp; ( `else` (
> [_BlockExpression_]
> | _IfExpression_
> | _IfLetExpression_ ) )<sup>\?</sup>
>
> _inIf_ :\
> &nbsp;&nbsp; ( `let` [_Pattern_] `=` [_Expression_]<sub>_except struct expression_</sub>
> | [_Expression_]<sub>_except struct expression_</sub>
> | _inIf_ )
>
> _inIfList_ :\
> &nbsp;&nbsp; _inIf_ ( && _inIf_ )*
[_Expression_]<sub>_except struct expression_</sub>

An `if` expression is a conditional branch in program control.
The syntax of an `if` expression is a condition operand, followed by a consequent block, any number of `else if` conditions and blocks, and an optional trailing `else` block.
Expand Down Expand Up @@ -126,7 +136,6 @@ if let E::X(n) | E::Y(n) = v {
```

The expression cannot be a [lazy boolean operator expression][_LazyBooleanOperatorExpression_].
Use of a lazy boolean operator is ambiguous with a planned feature change of the language (the implementation of if-let chains - see [eRFC 2947][_eRFCIfLetChain_]).
When lazy boolean operator expression is desired, this can be achieved by using parenthesis as below:

<!-- ignore: psuedo code -->
Expand All @@ -149,7 +158,6 @@ if let PAT = ( EXPR || EXPR ) { .. }
[_LazyBooleanOperatorExpression_]: operator-expr.md#lazy-boolean-operators
[_Pattern_]: ../patterns.md
[_Scrutinee_]: match-expr.md
[_eRFCIfLetChain_]: https://github.com/rust-lang/rfcs/blob/master/text/2497-if-let-chains.md#rollout-plan-and-transitioning-to-rust-2018
[`match` expression]: match-expr.md
[boolean type]: ../types/boolean.md
[scrutinee]: ../glossary.md#scrutinee

0 comments on commit 514d8b3

Please sign in to comment.