Skip to content

Commit

Permalink
Add if let to the reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Wieczorek committed Sep 30, 2014
1 parent 13e00e4 commit e53f4a6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/doc/reference.md
Expand Up @@ -3231,7 +3231,7 @@ for i in range(0u, 256) {
if_expr : "if" no_struct_literal_expr '{' block '}'
else_tail ? ;
else_tail : "else" [ if_expr
else_tail : "else" [ if_expr | if_let_expr
| '{' block '}' ] ;
```

Expand Down Expand Up @@ -3436,6 +3436,19 @@ let message = match maybe_digit {
};
```

### If let expressions

```{.ebnf .gram}
if_let_expr : "if" "let" pat '=' expr '{' block '}'
else_tail ? ;
else_tail : "else" [ if_expr | if_let_expr | '{' block '}' ] ;
```

An `if let` expression is semantically identical to an `if` expression but in place
of a condition expression it expects a refutable let statement. If the value of the
expression on the right hand side of the let statement matches the pattern, the corresponding
block will execute, otherwise flow proceeds to the first `else` block that follows.

### Return expressions

```{.ebnf .gram}
Expand Down

0 comments on commit e53f4a6

Please sign in to comment.