From ef2ebf4e8cde95cd16a15a8ef8990c5228e38be3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 1 Jul 2023 19:46:28 +0300 Subject: [PATCH] resolve: Update glob bindings in case of ambiguities (non-recursively) --- compiler/rustc_resolve/src/imports.rs | 2 ++ tests/ui/imports/duplicate.rs | 2 +- tests/ui/imports/duplicate.stderr | 22 +++++++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 074f761c53baa..7318630a0237d 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -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); } } (old_glob @ true, false) | (old_glob @ false, true) => { diff --git a/tests/ui/imports/duplicate.rs b/tests/ui/imports/duplicate.rs index db6538969ec71..0977bfef9aaa1 100644 --- a/tests/ui/imports/duplicate.rs +++ b/tests/ui/imports/duplicate.rs @@ -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 { diff --git a/tests/ui/imports/duplicate.stderr b/tests/ui/imports/duplicate.stderr index 997a2741b382c..33db11e3379c5 100644 --- a/tests/ui/imports/duplicate.stderr +++ b/tests/ui/imports/duplicate.stderr @@ -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 | @@ -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`.