-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
It is not intuitive which loop is broken out from in loop { while break {} }
#37576
Comments
While I agree that neither behaviour is exactly intuitive, I’d like to take some time to write down a number of intuitions that someone might use (perhaps helping to discuss the issue somewhat):
I personally see less issues with keeping the current behaviour over forbidding it (backward incompatibility) or changing it to the alternative (silent breaking change). |
loop { while break {} }
loop { while break {} }
Note that the current behavior is to forbid it unless its nested inside of another loop (!). I think forbiding it in every case is the best behavior; if you need to break in the condition, you can always write the desugared form. There is no clearly correct behavior of |
I would prefer forbidding regular |
One more data point re: existing behaviour... this is allowed: fn main() {
while let true = break {
unreachable!();
}
} (because the desugaring of |
Can #21751 be closed in favor of this? |
Here are some further examples that @cramertj raised in #39867. The current compiler does not have consistent treatment, in short, so I think that we can't really cite the "current behavior" as precedent one way or another:
|
This can be closed since #39864 has landed. |
From #37487 (comment)
cc @nikomatsakis and the lang team in general
UPDATE: See this comment which includes a number of examples that we will want to check when fixing this bug.
The text was updated successfully, but these errors were encountered: