Skip to content

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

Closed
wants to merge 2 commits into from
Closed

Add the loop_break_value feature to the reference #53

wants to merge 2 commits into from

Conversation

pietroalbini
Copy link
Member

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!

An inline code snippet was using triple quotes instead of single ones,
breaking syntax highlight in vim.
Copy link
Member

@steveklabnik steveklabnik left a 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.

@pietroalbini
Copy link
Member Author

The return value is ! when there's no break in the loop. If there's a break in it though, the return value can't be ! anymore because the loop can stop. In this case, before the return value was always (), and now it's the value provided to the break, which defaults to () anyway.

Copy link
Contributor

@Havvy Havvy left a 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.

@@ -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
Copy link
Contributor

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.

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
Copy link
Contributor

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 ()."

Copy link
Member Author

@pietroalbini pietroalbini May 16, 2017

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.

@@ -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
Copy link
Contributor

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;
  }
}

Copy link
Member Author

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.

Copy link
Contributor

@Havvy Havvy left a 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.

@@ -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
Copy link
Contributor

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.

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
Copy link
Contributor

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.
@dhardy
Copy link
Contributor

dhardy commented May 17, 2017

Continued in #56.

@dhardy dhardy mentioned this pull request May 17, 2017
@pietroalbini
Copy link
Member Author

Thanks for improving this @dhardy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants