Add the loop_break_value feature to the reference#53
Add the loop_break_value feature to the reference#53emilyalbini wants to merge 2 commits intorust-lang:masterfrom emilyalbini:feature/loop_break_value
Conversation
An inline code snippet was using triple quotes instead of single ones, breaking syntax highlight in vim.
steveklabnik
left a comment
There was a problem hiding this comment.
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 |
Havvy
left a comment
There was a problem hiding this comment.
Thanks for the additions. Here's two small things and a question I have. Overall, good additions.
src/expressions.md
Outdated
| 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.
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.
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.
Thanks! I'm not a native speaker so I'm still used to the italian idioms.
src/expressions.md
Outdated
| 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.
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.
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.
Havvy
left a comment
There was a problem hiding this comment.
Two minor grammar changes. Wording looks good to me.
src/expressions.md
Outdated
| 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.
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.
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_valuefeature, 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!