Skip to content

Document breaking out of a named code block #140197

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

Merged
merged 2 commits into from
May 2, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions library/std/src/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ mod as_keyword {}
/// println!("{result}");
/// ```
///
/// It is also possible to exit from any *labelled* block returning the value early.
/// If no value specified `break;` returns `()`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd stutter here. I think it should be "If no value is specified for" or "is given to", then "it returns ()".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a verbatim restatement of a sentence from the previous paragraph:

This is only valid with loop and not with any other type of loop.
If no value is specified, break; returns ().

It is also possible to exit from any labelled block returning the value early.
If no value specified break; returns ().

Does a comma suffice or should the text above be rephrased too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comma is the minimum for it to be valid, as far as I can tell. I do not think it is sufficient for it to be very comprehensible. So if you wish to revise both cases to be consistent, that is fine with me.

///
/// ```rust
/// let inputs = vec!["Cow", "Cat", "Dog", "Snake", "Cod"];
///
/// let mut results = vec![];
/// for input in inputs {
/// let result = 'filter: {
/// if input.len() > 3 {
/// break 'filter Err("Too long");
/// };
///
/// if !input.contains("C") {
/// break 'filter Err("No Cs");
/// };
///
/// Ok(input.to_uppercase())
/// };
///
/// results.push(result);
/// }
///
/// // [Ok("COW"), Ok("CAT"), Err("No Cs"), Err("Too long"), Ok("COD")]
/// println!("{:?}", results)
/// ```
///
/// For more details consult the [Reference on "break expression"] and the [Reference on "break and
/// loop values"].
///
Expand Down
Loading