Skip to content

Suggest introducing a labeled block when break is used outside of a loop, but inside a block #103982

Closed
@nagisa

Description

@nagisa

The following code:

fn main() {
    {
        break ();
    }
}

will output a diagnostic like this:

error[E0268]: `break` outside of a loop
 --> src/main.rs:3:9
  |
3 |         break;
  |         ^^^^^ cannot `break` outside of a loop

No loops in scope here, but there is a possible change that could be made besides adding a loop – introducing labels and breaking out of the enclosing block.

This is a followup to #103981

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-papercutDiagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions