-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Comments
Shorter test case: fn main() {
match Some(0) {
Some(_) => 'a: loop { break },
None => 'a: loop { break }
}
} Warnings:
|
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 |
It seems very clear to me. In which way could it be improved? |
Maybe "shadows another label already defined in this function"? |
@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? |
The linked PR #24162 intentionally makes duplicated labels emit a warning (even when they mark different scopes) |
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". |
Duplicate of #24278 |
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 scopeThe text was updated successfully, but these errors were encountered: