Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AaronC81 opened this issue Sep 23, 2021 · 1 comment
Closed

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

AaronC81 opened this issue Sep 23, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@AaronC81
Copy link
Contributor

AaronC81 commented Sep 23, 2021

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.

@AaronC81 AaronC81 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 23, 2021
@ehuss
Copy link
Contributor

ehuss commented Sep 23, 2021

This is currently intended behavior. See #21633 and https://internals.rust-lang.org/t/psa-rejecting-duplicate-loop-labels/1833 for more. There was an early intent that labels have function scope instead of block scope.

Closing as a duplicate of #31745, #81799, and #88225.

@ehuss ehuss closed this as completed Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants