Skip to content

Label-shadowing warning incorrectly calls a label 'lifetime' #79610

Closed
@nico-abram

Description

@nico-abram

When compiling the following code:

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

rust emits the following warning:

warning: label name `'a` shadows a label name that is already in scope
 --> src/main.rs:3:5
  |
2 |     'a: for _ in 0..1 { break 'a; }
  |     -- first declared here
3 |     'a: for _ in 0..1 { break 'a; }
  |     ^^ lifetime 'a already in scope

I tried nightly in the playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=eda5af652ad2b13204432834e1b67f8e and got the same output

lifetime 'a already in scope seems wrong, since 'a is not a lifetime, but a label

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.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