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

Ambiguous import not detected #97584

Closed
sander2 opened this issue May 31, 2022 · 7 comments
Closed

Ambiguous import not detected #97584

sander2 opened this issue May 31, 2022 · 7 comments
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically 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

@sander2
Copy link

sander2 commented May 31, 2022

I tried this code (playground):

use a::*;
mod a {
    pub use b::*;
    mod b {
        pub const SOME_VALUE: u32 = 1;
    }

    pub use c::*;
    mod c {
        pub const SOME_VALUE: u32 = 2;
    }
}
fn main() {
    assert_eq!(SOME_VALUE, 1);
}

I expected to see this happen: an error like error[E0659]: SOME_VALUE is ambiguous

Instead, this happened: the code compiles and runs to completion.

If you put the use a::* after the mod a, the expected error is thrown.

Meta

This happens both on stable and nightly.

@sander2 sander2 added the C-bug Category: This is a bug. label May 31, 2022
@SNCPlay42
Copy link
Contributor

This fails to compile (after adapting to 2015 edition) on 1.14 and compiles on 1.15 and later.

1.15 made changes to the name resolution rules as described in RFC 1560. The relevant part seems to be:

Multiple unused imports

A name may be imported multiple times, it is only a name resolution error if that name is used. E.g.,

mod foo {
   pub struct Qux;
}

mod bar {
  pub struct Qux;
}

mod baz {
   use foo::*;
   use bar::*; // Ok, no name conflict.
}

In this example, adding a use of Qux in baz would cause a name resolution error.

Attempting to lookup a::SOME_VALUE does indeed error. However the compiler appears to fail to consider what happens if a name that is ambiguous due to multiple imports is glob-imported into another module. As far as I can tell, it should still be ambiguous, but instead it appears the first import of the name "wins".

@rustbot label A-resolve regression-from-stable-to-stable

(Ancient regression, I know, but this issue should probably have a priority assigned anyway)

@rustbot rustbot added A-resolve Area: Name/path resolution done by `rustc_resolve` specifically regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 1, 2022
@inquisitivecrystal inquisitivecrystal added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 2, 2022
@apiraino
Copy link
Contributor

apiraino commented Jun 2, 2022

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@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 2, 2022
@SNCPlay42
Copy link
Contributor

I think this is a duplicate of #47525.

@apiraino
Copy link
Contributor

@SNCPlay42 would you prefer to close this in favor of #47525 (and working on that one instead)?

@sander2
Copy link
Author

sander2 commented Jun 27, 2022

I think this is a duplicate of #47525.

I think you're right. I'm ok with closing this issue then. Just note that the linked issue has different tags (enhancement vs bug, no priority, and no regression tag) which may have contributed in it being an open issue for 4 years

@apiraino
Copy link
Contributor

agreed, will update #47525 accordingly. Thanks!

@apiraino
Copy link
Contributor

Closing this in favor of #47525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically 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

No branches or pull requests

5 participants