From f7330eb752cdd83a9b944d1d64a092c7d2454c17 Mon Sep 17 00:00:00 2001 From: bohan Date: Wed, 14 Jun 2023 00:55:36 +0800 Subject: [PATCH] fix(resolve): update `shadowed_glob` more precision --- compiler/rustc_resolve/src/imports.rs | 16 +++++++++++++++- tests/ui/resolve/issue-105069.stderr | 4 +++- tests/ui/resolve/issue-109153.rs | 14 ++++++++++++++ tests/ui/resolve/issue-109153.stderr | 23 +++++++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/ui/resolve/issue-109153.rs create mode 100644 tests/ui/resolve/issue-109153.stderr diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 7f944fb574596..47d8e5993fd82 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -338,7 +338,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } else { resolution.binding = Some(nonglob_binding); } - resolution.shadowed_glob = Some(glob_binding); + + if let Some(old_binding) = resolution.shadowed_glob { + assert!(old_binding.is_glob_import()); + if glob_binding.res() != old_binding.res() { + resolution.shadowed_glob = Some(this.ambiguity( + AmbiguityKind::GlobVsGlob, + old_binding, + glob_binding, + )); + } else if !old_binding.vis.is_at_least(binding.vis, this.tcx) { + resolution.shadowed_glob = Some(glob_binding); + } + } else { + resolution.shadowed_glob = Some(glob_binding); + } } (false, false) => { return Err(old_binding); diff --git a/tests/ui/resolve/issue-105069.stderr b/tests/ui/resolve/issue-105069.stderr index 1e6c9c6e2dc34..a049cac830ab4 100644 --- a/tests/ui/resolve/issue-105069.stderr +++ b/tests/ui/resolve/issue-105069.stderr @@ -4,17 +4,19 @@ error[E0659]: `V` is ambiguous LL | use V; | ^ ambiguous name | - = note: ambiguous because of multiple potential import sources + = note: ambiguous because of multiple glob imports of a name in the same module note: `V` could refer to the variant imported here --> $DIR/issue-105069.rs:1:5 | LL | use self::A::*; | ^^^^^^^^^^ + = help: consider adding an explicit import of `V` to disambiguate note: `V` could also refer to the variant imported here --> $DIR/issue-105069.rs:3:5 | LL | use self::B::*; | ^^^^^^^^^^ + = help: consider adding an explicit import of `V` to disambiguate error: aborting due to previous error diff --git a/tests/ui/resolve/issue-109153.rs b/tests/ui/resolve/issue-109153.rs new file mode 100644 index 0000000000000..bff6c911236e6 --- /dev/null +++ b/tests/ui/resolve/issue-109153.rs @@ -0,0 +1,14 @@ +use foo::*; + +mod foo { + pub mod bar { + pub mod bar { + pub mod bar {} + } + } +} + +use bar::bar; //~ ERROR `bar` is ambiguous +use bar::*; + +fn main() { } diff --git a/tests/ui/resolve/issue-109153.stderr b/tests/ui/resolve/issue-109153.stderr new file mode 100644 index 0000000000000..1a345d2a3e3a7 --- /dev/null +++ b/tests/ui/resolve/issue-109153.stderr @@ -0,0 +1,23 @@ +error[E0659]: `bar` is ambiguous + --> $DIR/issue-109153.rs:11:5 + | +LL | use bar::bar; + | ^^^ ambiguous name + | + = note: ambiguous because of multiple glob imports of a name in the same module +note: `bar` could refer to the module imported here + --> $DIR/issue-109153.rs:1:5 + | +LL | use foo::*; + | ^^^^^^ + = help: consider adding an explicit import of `bar` to disambiguate +note: `bar` could also refer to the module imported here + --> $DIR/issue-109153.rs:12:5 + | +LL | use bar::*; + | ^^^^^^ + = help: consider adding an explicit import of `bar` to disambiguate + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0659`.