diff --git a/src/doc/reference.md b/src/doc/reference.md index 0500088bbdc0bc5f86933ad1d3611198e17cda29..14fc1d8d73d6869b1d280a215bf646b30e7a835e 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -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 '}' ] ; ``` @@ -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}