If a label is placed on the block of a loop instead of the header, suggest moving it to the header. by zachs18 · Pull Request #138589 · rust-lang/rust (original) (raw)

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Mar 20, 2025

@rust-timer

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.

fn main() {
    loop 'a: { return; }
}
 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: