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

Order of glob imports affects whether an ambiguity is reported #98467

Closed
SNCPlay42 opened this issue Jun 24, 2022 · 4 comments · Fixed by #113099
Closed

Order of glob imports affects whether an ambiguity is reported #98467

SNCPlay42 opened this issue Jun 24, 2022 · 4 comments · Fixed by #113099
Labels
A-resolve Area: Name resolution C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@SNCPlay42
Copy link
Contributor

The following code (2015 edition, a subset of /src/test/ui/imports/duplicate.rs, playground) compiles:

mod a {
    pub fn foo() {}
}

mod b {
    pub fn foo() {}
}

mod f {
    pub use a::*;
    pub use b::*;
}

mod g {
    pub use a::*;
    pub use f::*;
}

fn main() {
    g::foo();
}

If you reorder the glob imports in g, it does not compile (playground):

error[E0659]: `foo` is ambiguous
  --> src/main.rs:20:8
   |
20 |     g::foo();
   |        ^^^ ambiguous name
   |
   = note: ambiguous because of multiple glob imports of a name in the same module
note: `foo` could refer to the function imported here
  --> src/main.rs:10:13
   |
10 |     pub use a::*;
   |             ^^^^
   = help: consider adding an explicit import of `foo` to disambiguate
note: `foo` could also refer to the function imported here
  --> src/main.rs:11:13
   |
11 |     pub use b::*;
   |             ^^^^
   = help: consider adding an explicit import of `foo` to disambiguate

Both versions failed to compile prior to 1.32.0.

I found this while looking at #97584/#47525, which looks very related, but regressed earlier (1.15) - I have a WIP fix for that issue, but it fails on the linked UI test because it makes this error again. I'm mostly opening this to double-check that this change wasn't deliberate (since the change to the UI test's output was blessed).

@rustbot label C-bug T-compiler A-resolve regression-from-stable-to-stable

@rustbot rustbot added A-resolve Area: Name resolution C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 24, 2022
@SNCPlay42
Copy link
Contributor Author

I initially thought that perhaps the unambiguous import of a::foo via the glob pub use a::*; in g is supposed to "win" against the glob import of the ambiguous f::foo, but then I don't see why this should be order dependent.

@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 27, 2022
@SNCPlay42
Copy link
Contributor Author

SNCPlay42 commented Jun 27, 2022

I see on zulip there was some confusion surrounding the edition:

The 2018+ edition version of this code:

mod a {
    pub fn foo() {}
}

mod b {
    pub fn foo() {}
}

mod f {
    pub use crate::a::*;
    pub use crate::b::*;
}

mod g {
    pub use crate::a::*;
    pub use crate::f::*;
}

fn main() {
    g::foo();
}

still behaves the same way as the 2015 code, in that it compiles, but shouldn't (IMO), and is still dependent on the order of the uses in g in whether it errors or not.

@bvanjoi
Copy link
Contributor

bvanjoi commented Jul 2, 2023

related: #113242
related: #113099

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name resolution C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants