From 8d7e097d7ac17a2f9dc98b82d087f13104e30635 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Fri, 12 May 2017 11:51:34 +0200 Subject: [PATCH 1/2] Fix wrong quotes in the Expressions chapter An inline code snippet was using triple quotes instead of single ones, breaking syntax highlight in vim. --- src/expressions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/expressions.md b/src/expressions.md index df79faba75..244fb0af0d 100644 --- a/src/expressions.md +++ b/src/expressions.md @@ -564,7 +564,7 @@ Significantly, lambda expressions _capture their environment_, which regular [function definitions](items.html#functions) do not. The exact type of capture depends on the [function type](types.html#function-types) inferred for the lambda expression. In the simplest and least-expensive form (analogous to a -```|| { }``` expression), the lambda expression captures its environment by +`|| { }` expression), the lambda expression captures its environment by reference, effectively borrowing pointers to all outer variables mentioned inside the function. Alternately, the compiler may infer that a lambda expression should copy or move values (depending on their type) from the From f8dfbdc7c0b1bc9a054f797a3f84a08ad03fe418 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Fri, 12 May 2017 12:37:23 +0200 Subject: [PATCH 2/2] Add documentation for loop_break_value This commit introduces to the reference the changes made by the loop_break_value feature, defined in RFC 1624. --- src/expressions.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/expressions.md b/src/expressions.md index 244fb0af0d..b269c52a19 100644 --- a/src/expressions.md +++ b/src/expressions.md @@ -600,6 +600,11 @@ within this loop may exit out of this loop or return control to its head. See [break expressions](#break-expressions) and [continue expressions](#continue-expressions). +A `loop` expression is [diverging](items.html#diverging-functions), and doesn't +return anything. However, when it contains a [break +expression](#break-expressions), it returns the value attached to the `break` +that caused the loop to stop. + ## `break` expressions A `break` expression has an optional _label_. If the label is absent, then @@ -608,6 +613,14 @@ enclosing it. It is only permitted in the body of a loop. If the label is present, then `break 'foo` terminates the loop with label `'foo`, which need not be the innermost label enclosing the `break` expression, but must enclose it. +When the `break` expression is enclosed in a `loop` it has an optional return +value attached which will be returned by the loop ended by the +expression. When it's not provided it defaults to `()`. + +If both a label and a return value are present in the expression, the label +must be placed before the return value. For example `break 'label 42` breaks +the loop labelled `'label`, returning `42` from it. + ## `continue` expressions A `continue` expression has an optional _label_. If the label is absent, then