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 warning about label shadowing itself #25343

Closed
nstoddard opened this issue May 12, 2015 · 1 comment · Fixed by #27093
Closed

Incorrect warning about label shadowing itself #25343

nstoddard opened this issue May 12, 2015 · 1 comment · Fixed by #27093
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@nstoddard
Copy link

The following code:

fn main() {
    || {
        'label: loop {
        }
    };
}

Results in this warning:

main.rs:3:17: 4:10 warning: label name `'label` shadows a label name that is already in scope
main.rs:3         'label: loop {
main.rs:4         }
main.rs:3:17: 4:10 note: shadowed label `'label` declared here
main.rs:3         'label: loop {
main.rs:4         }

Obviously a label can't shadow itself, so there shouldn't be a warning. The issue doesn't occur outside of a closure.

@pnkfelix pnkfelix self-assigned this May 12, 2015
@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label May 13, 2015
@mitchmindtree
Copy link
Contributor

I just came across this one myself, just thought I'd +1

bors added a commit that referenced this issue Jul 21, 2015
Fixes #25343

To be honest I'm not sure if this is the right fix (I haven't yet fully understood the code),
but it seems to work. I'll look closer at the code when I have some time, in the meantime if this
is the right fix it would be nice to get verification from someone who does understand the code 😄

r? @pnkfelix
birkenfeld added a commit to birkenfeld/rust that referenced this issue May 2, 2016
This should fix rust-lang#31754 and follow-up rust-lang#25343.  Before the latter, the
closure was visited twice in the context of the enclosing fn, which
made even a single closure with a loop label emit a warning.

With this change, the closure is still visited within the context
of the main fn (which is intended, since it is not a separate item)
but resets the found loop labels while being visited.

Fixes: rust-lang#31754
steveklabnik added a commit to steveklabnik/rust that referenced this issue May 10, 2016
middle: reset loop labels while visiting closure

This should fix rust-lang#31754 and follow-up rust-lang#25343.  Before the latter, the closure was visited twice in the context of the enclosing fn, which made even a single closure with a loop label emit a warning.

With this change, the closure is still visited within the context of the main fn (which is intended, since it is not a separate item) but resets the found loop labels while being visited.

Fixes: rust-lang#31754

Note: I amended the test file from rust-lang#25343, but I don't know if the original or amended test are effective, since as far as I could see, compiletest's run-pass tests do not check for zero warnings emitted?

/cc @Manishearth
steveklabnik added a commit to steveklabnik/rust that referenced this issue May 10, 2016
middle: reset loop labels while visiting closure

This should fix rust-lang#31754 and follow-up rust-lang#25343.  Before the latter, the closure was visited twice in the context of the enclosing fn, which made even a single closure with a loop label emit a warning.

With this change, the closure is still visited within the context of the main fn (which is intended, since it is not a separate item) but resets the found loop labels while being visited.

Fixes: rust-lang#31754

Note: I amended the test file from rust-lang#25343, but I don't know if the original or amended test are effective, since as far as I could see, compiletest's run-pass tests do not check for zero warnings emitted?

/cc @Manishearth
steveklabnik added a commit to steveklabnik/rust that referenced this issue May 11, 2016
middle: reset loop labels while visiting closure

This should fix rust-lang#31754 and follow-up rust-lang#25343.  Before the latter, the closure was visited twice in the context of the enclosing fn, which made even a single closure with a loop label emit a warning.

With this change, the closure is still visited within the context of the main fn (which is intended, since it is not a separate item) but resets the found loop labels while being visited.

Fixes: rust-lang#31754

Note: I amended the test file from rust-lang#25343, but I don't know if the original or amended test are effective, since as far as I could see, compiletest's run-pass tests do not check for zero warnings emitted?

/cc @Manishearth
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants