rust-lang / rust-lang/rust

`continue` expressions in loop conditions

Open
#118,673 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-docs C-bug I-lang-radar T-lang
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Reference's loop-expressions section at the linked continue-expressions entry, then compare its rule with the labeled and unlabeled examples in the issue. Check rustc --explain E0590 and the reported compiler behavior; done means the intended rule is decided and the Reference and compiler behavior no longer conflict.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.