Skip to content

Incorrect label shadow warning #88225

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

Closed
WiSaGaN opened this issue Aug 22, 2021 · 3 comments
Closed

Incorrect label shadow warning #88225

WiSaGaN opened this issue Aug 22, 2021 · 3 comments
Labels
C-bug Category: This is a bug.

Comments

@WiSaGaN
Copy link
Contributor

WiSaGaN commented Aug 22, 2021

I tried this code:

fn main() {
    if true {
        'l : loop {
            break 'l;
        }
    } else {
        'l : loop {
            break 'l;
        }
    }
}

I expected to see this happen: no warning regarding to label

Instead, this happened: got warning about label shadowing

warning: label name `'l` shadows a label name that is already in scope
 --> src/main.rs:7:9
  |
3 |         'l : loop {
  |         -- first declared here
...
7 |         'l : loop {
  |         ^^ label `'l` already in scope

version

Build using the Nightly version: 1.56.0-nightly

(2021-08-21 d3e2578c31688619ddc0)

playground

@WiSaGaN WiSaGaN added the C-bug Category: This is a bug. label Aug 22, 2021
@ehuss
Copy link
Contributor

ehuss commented Aug 22, 2021

Thanks for the report! This is currently intentional, and a known issue. The warning could be clearer, though. Closing as a duplicate of #24278 and #31745.

@ehuss ehuss closed this as completed Aug 22, 2021
@WiSaGaN
Copy link
Contributor Author

WiSaGaN commented Aug 23, 2021

Ok. I digged up an exact duplicate here: #81799

This warning is very unintuitive. I got that this is intended in the links provided, but could not find out why, i.e. what harm does it do if I write it this way. @ehuss can you provide a link to the reason why this is intended that this can be discussed?

@ehuss
Copy link
Contributor

ehuss commented Aug 23, 2021

I don't think there is any information beyond what is linked in those issues. This was something added before 1.0, and it hasn't been revisited since. The why is primarily explained in https://internals.rust-lang.org/t/psa-rejecting-duplicate-loop-labels/1833, where there was an intent to add explicit syntax for labeling a region for a borrow, but that never got beyond the idea stage (AFAIK). #24278 also explains how there are macro hygiene problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants