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

Erroneous warning for loop name shadowing in separate match arms #30359

Closed
insanitybit opened this issue Dec 13, 2015 · 8 comments
Closed

Erroneous warning for loop name shadowing in separate match arms #30359

insanitybit opened this issue Dec 13, 2015 · 8 comments

Comments

@insanitybit
Copy link

http://is.gd/XAabFg

Despite the loop names not shadowing each other, as they exist within separate match arms, there's a warning for this code.

:13:13: 15:14 warning: label name 'l shadows a label name that is already in scope

@utkarshkukreti
Copy link
Contributor

Shorter test case:

fn main() {
    match Some(0) {
        Some(_) => 'a: loop { break },
        None    => 'a: loop { break }
    }
}

Warnings:

<anon>:4:20: 4:38 warning: label name `'a` shadows a label name that is already in scope
<anon>:4         None    => 'a: loop { break }
                            ^~~~~~~~~~~~~~~~~~
<anon>:3:20: 3:38 note: shadowed label `'a` declared here
<anon>:3         Some(_) => 'a: loop { break },

@petrochenkov
Copy link
Contributor

This is intentional (at least currently). Labels in a function are supposed to be uniquely named regardless of scoping. The warning message could be better though.

cc #24162

@GuillaumeGomez
Copy link
Member

It seems very clear to me. In which way could it be improved?

@jonas-schievink
Copy link
Contributor

Maybe "shadows another label already defined in this function"?

@GuillaumeGomez
Copy link
Member

@jonas-schievink: That cannot be this because a scope is more precise than a function. Example:

fn labels() {
    {
        'a: for i in 0..10 {}
    }
    {
        'a: for i in 0..10 {}
    }
}

Same function, but not same scopes. Do you understand better?

@jonas-schievink
Copy link
Contributor

The linked PR #24162 intentionally makes duplicated labels emit a warning (even when they mark different scopes)

@GuillaumeGomez
Copy link
Member

Hum... Well then, if you want to avoid this in a function scope, the better would then be to add a help message after the warning: "To keep your code easy to read an maintain, try to avoid using the same label name in a function scope".

@petrochenkov
Copy link
Contributor

Duplicate of #24278

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants