Skip to content

Loop label is mistaken for a lifetime in lexer error #46311

Closed
@martinhath

Description

@martinhath

Consider the following code:

fn main() {
    'break: loop {
    }
}

The loop label is illegal, as it is a reserved keyword. The compiler recognizes this, but the error message claims 'break to be a lifetime, and not a loop label:

   Compiling playground v0.0.1 (file:///playground)
error: lifetimes cannot use keyword names
 --> src/main.rs:2:6
  |
2 |     'break: loop {
  |      ^^^^^

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

I took a quick look in libsyntax, and it seems that the problem is that 'break and : are two tokens, and that we don't figure out that it's a label instead of a lifetime until parsing.

Meta

This applies to stable, beta, nightly, and presumably master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions