Skip to content

continue expressions in loop conditions #118673

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

Open
raimondsrainskis opened this issue Dec 6, 2023 · 4 comments
Open

continue expressions in loop conditions #118673

raimondsrainskis opened this issue Dec 6, 2023 · 4 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. T-lang Relevant to the language team

Comments

@raimondsrainskis
Copy link

raimondsrainskis commented Dec 6, 2023

Location

https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions

Summary

The reference unambiguously states that "A continue expression is only permitted in the body of a loop.", but this is demonstrably not true for continue 'label expressions.

The following compiles and runs an infinite loop. A warning mentions the body being unreachable, but otherwise the behavior is as one would expect:

'a: while continue 'a {}

Meanwhile, the following does not compile:

while { continue; true } {}

In the second example, an error is generated:

error[E0590]: break or continue with no label in the condition of a while loop

Furthermore, rustc --explain E0590 demonstrates label usage with a break expression:

'foo: while break 'foo {}

Unless I have misunderstood something, there seems to be conflicting information between the reference and the actual behavior of the compiler.

Edit: grammar.

@raimondsrainskis raimondsrainskis added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Dec 6, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 6, 2023
@saethlin saethlin added C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 7, 2023
@lolbinarycat lolbinarycat added the T-lang Relevant to the language team label Mar 31, 2025
@traviscross traviscross added I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-2 Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. P-lang-drag-3 Lang team prioritization drag level 3.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. and removed P-lang-drag-2 Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. labels May 19, 2025
@traviscross
Copy link
Contributor

Personally, I wouldn't expect us to accept 'a: while continue 'a {} unless we were to also accept 'a: { continue 'a }.

@theemathas
Copy link
Contributor

See also #121623, where rust doesn't properly handle 'a: { continue 'a }

@theemathas

This comment has been minimized.

@traviscross
Copy link
Contributor

traviscross commented May 28, 2025

@rustbot labels -I-lang-nominated +I-lang-radar -P-lang-drag-3

We talked about this today in triage briefly.

Probably I would prefer to make this consistent by allowing backward jumps to labels, generally, within labeled blocks, just as we allow forward jumps to labels (i.e. 'a: { continue 'a }). Probably the next step is for someone to write that up and propose it.

@rustbot rustbot added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. and removed I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-3 Lang team prioritization drag level 3.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. labels May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. T-lang Relevant to the language team
Projects
None yet
Development

No branches or pull requests

6 participants