Skip to content

Reserving "nobreak" as a keyword for Rust Edition 2021 #3152

Closed
@JelteF

Description

@JelteF

The reason I'm opening this issue is that there has been some activity on the old issues, regarding returning values with break from for and while loops:

  1. Allow loops to return values other than () #961
  2. Allow for and while loop to return value (without discussion of keyword names) #1767

Rereading those threads, the main issues why those were originally closed seem to be:

  1. else being a confusing name for this block
  2. not being able to add a new keyword that makes the meaning of the block clear
  3. there was no experience with the loop version of the break <value> syntax

Number 1 is still valid (although some disagree). 3 is not valid anymore, this feature was stabilized more than 4 years ago in 2017. Number 2 seems much less of a problem these days, since we now have editions (which we didn't have when these original issues were opened).

That's why I'm proposing to reserve nobreak as a keyword in Rust Edition 2021. That way we at can add this feature in the future, using a clear keyword.

I think nobreak clearly shows the meaning of the block. It's the block that you enter when there was no break. Code would then look like this:

let found_six = for val in [1, 4, 3, 2] {
    if val == 6 {
        break true;
    }
} nobreak {
    false
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions