-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Glob Time Travel #74556
Comments
Shadowing a glob import with a specific item is allowed and will unambiguously resolve to the specific one. This is also how the prelude works. The following compiles fine as well: // implicit: use std::prelude::v1::*; containing Vec
struct Vec;
fn a() -> Vec { unimplemented!() } |
To clarify, the problem is not shadowing, but time travel. We shadow identifier which have been already used to resolve another import, so we end up with |
This is a change from Rust 1.44, in Rust 1.43 this is an ICE "inconsistent resolution for an import". |
I'm not sure this is a bug. When resolving If you take this detail into consideration, then all paths seem to be resolved correctly. |
cc #62769 (somewhat related) |
I think, the difference with In my example, I can complicate my example a bit. mod foo {
pub mod bar {
pub mod bar {
pub fn foobar() { println!("111") }
}
pub fn foobar() { println!("222") }
}
}
use foo::*;
use bar::bar;
use bar::foobar;
fn main() {
foobar();
} What this program prints, "111" or "222"? It'd say, it depends on imports resolution order, but looks like it always prints "111". |
The intent for the resolution results is to never depend on internal resolution order.
That's what I'd expect.
|
I'd still be ok with replacing the former ICE with an error though, since that's a more conservative choice. |
Actually enabling the property "name resolve to the same thing whether some items were excluded during its resolution to avoid cycles or not" may be useful for using something like "inference variables" for unresolved imports and making import resolution more like unification in type inference. That's an idea I had for quite some, but I hadn't realized that merging #70236 went against it. |
Sigh, the issue already affects three stable releases - from 1.44 to 1.46. |
Addressed in #77421. |
Assigning |
The fix caused some regressions - #77586. |
@petrochenkov The code in the issue produce no errors using Rust 1.67.1. Should we re-open the issue or is it not considered a bug now? |
@vlad20012 |
(Also it's not exactly a time travel - #77586 (comment).) |
I tried this code:
I expected to see this happen: Compilation error. This
use bar::bar;
shadows one (glob-imported)bar
with anotherbar
. As far as I know, this should be forbidden.Instead, this happened: this code successfully compiled.
Meta
rustc --version --verbose
:c.c. @matklad
c.c. @petrochenkov
The text was updated successfully, but these errors were encountered: