Skip to content

Incorrect "label name shadows a name already in scope" warning #89192

Closed
@AaronC81

Description

@AaronC81

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=88ae8b7f1d4eb4b2fb318e957cd3695d

fn foo(x: u32) {
    match x {
        1 => {
            'outer: loop { break 'outer }
        }
        _ => {
            'outer: loop { break 'outer }
        }
    }
}

The current output is:

warning: label name `'outer` shadows a label name that is already in scope
 --> src/lib.rs:7:13
  |
4 |             'outer: loop { break 'outer }
  |             ------ first declared here
...
7 |             'outer: loop { break 'outer }
  |             ^^^^^^ label `'outer` already in scope

I don't think this warning should be emitted, since as far as I understand there's no valid way that one match arm's 'outer label could be used from the other match arm. So I don't think there is shadowing taking place here, but rather defining two entirely separate labels in two entirely separate scopes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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