-
Notifications
You must be signed in to change notification settings - Fork 533
Add the loop_break_value feature to the reference #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the loop_break_value feature to the reference #53
Conversation
An inline code snippet was using triple quotes instead of single ones, breaking syntax highlight in vim.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me. One tiny question: it says that the return value is !
, but also that it is ()
. Is this because ()
satisfies !
, or is this a mistake of some kind? I should re-read the RFC.
The return value is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the additions. Here's two small things and a question I have. Overall, good additions.
src/expressions.md
Outdated
@@ -600,6 +600,12 @@ 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). | |||
|
|||
The return value of a `loop` expression is `!`, which can be coerced to any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of saying that !
can be coerced to any type here, perhaps just link to the section on diverging functions.
src/expressions.md
Outdated
The return value of a `loop` expression is `!`, which can be coerced to any | ||
type. However, if there is a `break` expression in the loop, the return value | ||
of the loop becomes the one of the value provided to the [break | ||
expression](#break-expressions) causing the loop to end, which is `()` by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comma there is improper English. I think it'd flow better with the information in its own sentence though. Perhaps "When the break expression has no return value it defaults to ()
."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'm not a native speaker so I'm still used to the italian idioms.
src/expressions.md
Outdated
@@ -600,6 +600,12 @@ 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). | |||
|
|||
The return value of a `loop` expression is `!`, which can be coerced to any | |||
type. However, if there is a `break` expression in the loop, the return value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the break
expression have to also break for the loop it's in? For instance, I would expect 'inner
to still be considered diverging here? I'm not actually sure though.
'outer loop {
'inner loop {
break 'outer;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't write the implementation for the feature so I'm not sure, but I guess 'inner
is not diverging, and has a return value of ()
, because it actually returns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor grammar changes. Wording looks good to me.
src/expressions.md
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both commas in this sentence can be removed.
src/expressions.md
Outdated
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 put before the return value. For example `break 'label 42` breaks the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change put
to placed
, I think?
This commit introduces to the reference the changes made by the loop_break_value feature, defined in RFC 1624.
Continued in #56. |
Thanks for improving this @dhardy! |
I added to the reference the changes made by the
loop_break_value
feature, which was accepted to be stabilized in rust-lang/rust#37339. As far as I can tell I added everything needed, but this is the first time I add something to the reference so it's quite possible I missed something!