Skip to content

Commit e53f4a6

Browse files
author
Jakub Wieczorek
committed
Add if let to the reference
1 parent 13e00e4 commit e53f4a6

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/doc/reference.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3231,7 +3231,7 @@ for i in range(0u, 256) {
32313231
if_expr : "if" no_struct_literal_expr '{' block '}'
32323232
else_tail ? ;
32333233
3234-
else_tail : "else" [ if_expr
3234+
else_tail : "else" [ if_expr | if_let_expr
32353235
| '{' block '}' ] ;
32363236
```
32373237

@@ -3436,6 +3436,19 @@ let message = match maybe_digit {
34363436
};
34373437
```
34383438

3439+
### If let expressions
3440+
3441+
```{.ebnf .gram}
3442+
if_let_expr : "if" "let" pat '=' expr '{' block '}'
3443+
else_tail ? ;
3444+
else_tail : "else" [ if_expr | if_let_expr | '{' block '}' ] ;
3445+
```
3446+
3447+
An `if let` expression is semantically identical to an `if` expression but in place
3448+
of a condition expression it expects a refutable let statement. If the value of the
3449+
expression on the right hand side of the let statement matches the pattern, the corresponding
3450+
block will execute, otherwise flow proceeds to the first `else` block that follows.
3451+
34393452
### Return expressions
34403453

34413454
```{.ebnf .gram}

0 commit comments

Comments
 (0)