-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Fix resolution of local items that shadow imported ones #5418
Fix resolution of local items that shadow imported ones #5418
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definitely fixes a bug, but there's still an issue when the imported declaration is used before the local declaration:
use lib::Enum;
pub const Y: Enum = Enum::A;
enum Enum {
A: (),
B: (),
}
The type Enum
in the declaration of Y
resolves to the locally defined type rather than the imported one.
It's probably intentional that type declarations are in scope in the entire file, but I was surprised to see it resolve this way, so maybe it's worth it to issue a warning when a used type name has multiple resolutions?
In any case the scope of type declarations is unclear from the documentation.
...src/e2e_vm_tests/test_programs/should_pass/resolve_local_items_that_shadow_imports/test.toml
Show resolved
Hide resolved
This is actually expected behavior. Items follow item-style shadowing and not sequential shadowing. They are visible in the whole module no matter where they are declared. E.g.: fn first() {
second();
}
fn second() {
let _ = Enum::A;
}
enum Enum {
A: (),
} Which means In the above example we will also get an error for the name clash, but the resolution should still be to the local one, because the shadowing is not sequential but item-style. To item-style shadowing and sequential shadowing, I like the explanation/definitions given in the Rust RFC 116 (No module shadowing). |
"Due to a certain lack of official, clearly defined semantics and terminology, ..." Suffice it to say I don't. :-) |
Well, as long as we don't have anything better... 😄 |
Description
Closes #5383.
#5383 blocks PR #5306.
Checklist
Breaking*
orNew Feature
labels where relevant.