Skip to content
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

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

Closed
nagisa opened this issue Nov 4, 2022 · 1 comment · Fixed by #103994
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-papercut Diagnostics: An error or lint that needs small tweaks.

Comments

@nagisa
Copy link
Member

nagisa commented Nov 4, 2022

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...

@nagisa nagisa added D-papercut Diagnostics: An error or lint that needs small tweaks. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Nov 4, 2022
@compiler-errors
Copy link
Member

(just my 2¢, but I actually think "cannot break outside of a loop or labeled block" is totally fine for now.)

@compiler-errors compiler-errors added the A-diagnostics Area: Messages for errors, warnings, and lints label Nov 4, 2022
@bors bors closed this as completed in 61553d1 Nov 5, 2022
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
Specify that `break` cannot be used outside of loop *or* labeled block

Closes rust-lang#103981

`@rustbot` label +A-diagnostics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-papercut Diagnostics: An error or lint that needs small tweaks.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants