Skip to content

resolve: Update glob bindings in case of ambiguities (non-recursively) #113240

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
} else if !old_binding.vis.is_at_least(binding.vis, this.tcx) {
// We are glob-importing the same item but with greater visibility.
resolution.binding = Some(binding);
} else if binding.is_ambiguity() {
resolution.binding = Some(binding);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it solve #112713? I'm not sure.

}
}
(old_glob @ true, false) | (old_glob @ false, true) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/imports/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod g {
fn main() {
e::foo();
f::foo(); //~ ERROR `foo` is ambiguous
g::foo();
g::foo(); //~ ERROR `foo` is ambiguous
}

mod ambiguous_module_errors {
Expand Down
22 changes: 21 additions & 1 deletion tests/ui/imports/duplicate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ LL | pub use b::*;
| ^^^^
= help: consider adding an explicit import of `foo` to disambiguate

error[E0659]: `foo` is ambiguous
--> $DIR/duplicate.rs:36:8
|
LL | 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
--> $DIR/duplicate.rs:24:13
|
LL | pub use a::*;
| ^^^^
= help: consider adding an explicit import of `foo` to disambiguate
note: `foo` could also refer to the function imported here
--> $DIR/duplicate.rs:25:13
|
LL | pub use b::*;
| ^^^^
= help: consider adding an explicit import of `foo` to disambiguate

error[E0659]: `foo` is ambiguous
--> $DIR/duplicate.rs:49:9
|
Expand All @@ -68,7 +88,7 @@ LL | use self::m2::*;
| ^^^^^^^^^^^
= help: consider adding an explicit import of `foo` to disambiguate

error: aborting due to 4 previous errors
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0252, E0659.
For more information about an error, try `rustc --explain E0252`.