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

"block label not supported here" when the label is in the wrong place #138585

Closed
kpreid opened this issue Mar 17, 2025 · 1 comment · Fixed by #138589
Closed

"block label not supported here" when the label is in the wrong place #138585

kpreid opened this issue Mar 17, 2025 · 1 comment · Fixed by #138589
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kpreid
Copy link
Contributor

kpreid commented Mar 17, 2025

Code

fn main() {
    loop 'a: { return; }
}

Current output

error: block label not supported here
 --> src/main.rs:2:10
  |
2 |     loop 'a: { return; }
  |          ^^^ not supported here

Desired output

error: misplaced loop label
 --> src/main.rs:2:10
  |
2 |     loop 'a: { return; }
  |          ^^^ not supported here
  help: change this to `'a: loop {`

Rust Version

1.85.0

@kpreid kpreid added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 17, 2025
@zachs18
Copy link
Contributor

zachs18 commented Mar 17, 2025

@rustbot claim

@bors bors closed this as completed in c3f74bc Mar 20, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 20, 2025
Rollup merge of rust-lang#138589 - zachs18:block-label-not-supported-here-loop-body-help, r=petrochenkov

If a label is placed on the block of a loop instead of the header, suggest moving it to the header.

Fixes rust-lang#138585

If a label is placed on the block of a loop instead of the header, suggest to the user moving it to the loop header instead of ~~suggesting to remove it~~ emitting a tool-only suggestion to remove it.

```rs
fn main() {
    loop 'a: { return; }
}
```

```diff
 error: block label not supported here
  --> src/main.rs:2:10
   |
 2 |     loop 'a: { return; }
   |          ^^^ not supported here
+  |
+help: if you meant to label the loop, move this label before the loop
+  |
+2 -     loop 'a: { return; }
+2 +     'a: loop { return; }
+  |
```

Questions for reviewer:

* The "desired output" in the linked issue had the main diagnostic be "misplaced loop label". Should the main diagnostic message the changed instead of leaving it as "block label not supported here"?
* Should this be `Applicability::MachineApplicable`?
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants