Skip to content

Labeled break outside of breakable frames says break cannot be used outside of a loop #103981

Closed
@nagisa

Description

@nagisa
fn main() {
    break 'foo;
}

Will output the following diagnostics:

error[E0426]: use of undeclared label `'foo`
 --> src/main.rs:2:11
  |
2 |     break 'foo;
  |           ^^^^ undeclared label `'foo`

error[E0268]: `break` outside of a loop
 --> src/main.rs:2:5
  |
2 |     break 'foo;
  |     ^^^^^^^^^^ cannot `break` outside of a loop

With break now supported in conjunction with non-loop constructs, we should adjust this diagnostic accordingly. The wording here might be tricky, because something like

cannot break outside of a loop or a labeled block

would go stale as soon as we add another thing/place you can break out of, and the wording in general reads awkward regardless...

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-papercutDiagnostics: An error or lint that needs small tweaks.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions