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

[ER] Better error message for wrongly written break label #79424

Closed
leonardo-m opened this issue Nov 25, 2020 · 1 comment · Fixed by #80023
Closed

[ER] Better error message for wrongly written break label #79424

leonardo-m opened this issue Nov 25, 2020 · 1 comment · Fixed by #80023
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@leonardo-m
Copy link

leonardo-m commented Nov 25, 2020

This is an enhancement request. This code is wrong because it lacks a ':

fn main() {
    'LOOP: for _ in 0 .. 9 {
        break LOOP;
    }
}

It gives the error messages (rustc 1.50.0-nightly 1c389ff 2020-11-24):

error[E0425]: cannot find value `LOOP` in this scope
 --> ...test.rs:3:15
  |
3 |         break LOOP;
  |               ^^^^ not found in this scope

warning: unused label
 --> ...test.rs:2:5
  |
2 |     'LOOP: for _ in 0 .. 9 {
  |     ^^^^^
  |
  = note: `#[warn(unused_labels)]` on by default

error[E0571]: `break` with value from a `for` loop
 --> ...test.rs:3:9
  |
3 |         break LOOP;
  |         ^^^^^^^^^^ can only break with a value inside `loop` or breakable block
  |
help: instead, use `break` on its own without a value inside this `for` loop
  |
3 |         break;
  |         ^^^^^

error: aborting due to 2 previous errors; 1 warning emitted

But in such case I think it's better for the compiler to recognize in the error messages that the problem is probably just a lack of ' instead.

@camelid camelid added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Nov 25, 2020
@sasurau4
Copy link
Contributor

I'll try it.
@rustbot claim

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 C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants