Skip to content

break inside gen blocks misidentifies gen block as a closure #124495

Closed

Description

@dtolnay

Code

#![feature(gen_blocks)]

fn main() {
    let _ = || break;
    let _ = async { break };
    let _ = gen { break };
}

Current output

error[E0267]: `break` inside of a closure
 --> src/main.rs:4:16
  |
4 |     let _ = || break;
  |             -- ^^^^^ cannot `break` inside of a closure
  |             |
  |             enclosing closure

error[E0267]: `break` inside of an `async` block
 --> src/main.rs:5:21
  |
5 |     let _ = async { break };
  |             --------^^^^^--
  |             |       |
  |             |       cannot `break` inside of an `async` block
  |             enclosing `async` block

error[E0267]: `break` inside of a closure
 --> src/main.rs:6:19
  |
6 |     let _ = gen { break };
  |             ------^^^^^--
  |             |     |
  |             |     cannot `break` inside of a closure
  |             enclosing closure

Desired output

...

error[E0267]: `break` inside of a `gen` block
 --> src/main.rs:6:19
  |
6 |     let _ = gen { break };
  |             ------^^^^^--
  |             |     |
  |             |     cannot `break` inside of a `gen` block
  |             enclosing `gen` block

Rationale and extra context

Same issue as #63391 which was for async blocks.

Rust Version

rustc 1.79.0-nightly (aed2187d5 2024-04-27)
binary: rustc
commit-hash: aed2187d53b8789e3a37f50ae36f894a2a679077
commit-date: 2024-04-27
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    F-gen_blocks`gen {}` expressions that produce `Iterator`s
    on Apr 28, 2024
  2. veera-sivarajan commented on May 5, 2024

    @veera-sivarajan
    Contributor

    @rustbot claim

  3. added a commit that references this issue on May 9, 2024
    9b834d0
  4. added a commit that references this issue on May 9, 2024
    6248584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsF-gen_blocks`gen {}` expressions that produce `Iterator`sT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions