Skip to content

Account for missing ' in break tags #81192

Closed
@estebank

Description

@estebank

Given

fn main() {
    'a: for _ in 0..1 {
        break 'a;
    }
    'b: for _ in 0..1 {
        break b;
    }
    c: for _ in 0..1 {
        break 'c;
    }
    d: for _ in 0..1 {
        break d;
    }
}

the current output is

error: expected identifier, found keyword `for`
 --> src/main.rs:8:8
  |
8 |     c: for _ in 0..1 {
  |        ^^^ expected identifier, found keyword

error: expected `<`, found reserved identifier `_`
 --> src/main.rs:8:12
  |
8 |     c: for _ in 0..1 {
  |      -     ^ expected `<`
  |      |
  |      tried to parse a type due to this type ascription
  |
  = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
  = note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information

error[E0425]: cannot find value `b` in this scope
 --> src/main.rs:6:15
  |
6 |         break b;
  |               ^
  |               |
  |               not found in this scope
  |               help: a label with a similar name exists: `'b`

warning: unused label
 --> src/main.rs:5:5
  |
5 |     'b: for _ in 0..1 {
  |     ^^
  |
  = note: `#[warn(unused_labels)]` on by default

error[E0571]: `break` with value from a `for` loop
 --> src/main.rs:6:9
  |
6 |         break b;
  |         ^^^^^^^ 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
  |
6 |         break;
  |         ^^^^^

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

It should instead be 5 errors with appropriate suggestions to add the missing ' to the tags.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTD-confusingDiagnostics: Confusing error or lint that should be reworked.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