Skip to content

Commit f7330eb

Browse files
committed
fix(resolve): update shadowed_glob more precision
1 parent 4bd4e2e commit f7330eb

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

compiler/rustc_resolve/src/imports.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
338338
} else {
339339
resolution.binding = Some(nonglob_binding);
340340
}
341-
resolution.shadowed_glob = Some(glob_binding);
341+
342+
if let Some(old_binding) = resolution.shadowed_glob {
343+
assert!(old_binding.is_glob_import());
344+
if glob_binding.res() != old_binding.res() {
345+
resolution.shadowed_glob = Some(this.ambiguity(
346+
AmbiguityKind::GlobVsGlob,
347+
old_binding,
348+
glob_binding,
349+
));
350+
} else if !old_binding.vis.is_at_least(binding.vis, this.tcx) {
351+
resolution.shadowed_glob = Some(glob_binding);
352+
}
353+
} else {
354+
resolution.shadowed_glob = Some(glob_binding);
355+
}
342356
}
343357
(false, false) => {
344358
return Err(old_binding);

tests/ui/resolve/issue-105069.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ error[E0659]: `V` is ambiguous
44
LL | use V;
55
| ^ ambiguous name
66
|
7-
= note: ambiguous because of multiple potential import sources
7+
= note: ambiguous because of multiple glob imports of a name in the same module
88
note: `V` could refer to the variant imported here
99
--> $DIR/issue-105069.rs:1:5
1010
|
1111
LL | use self::A::*;
1212
| ^^^^^^^^^^
13+
= help: consider adding an explicit import of `V` to disambiguate
1314
note: `V` could also refer to the variant imported here
1415
--> $DIR/issue-105069.rs:3:5
1516
|
1617
LL | use self::B::*;
1718
| ^^^^^^^^^^
19+
= help: consider adding an explicit import of `V` to disambiguate
1820

1921
error: aborting due to previous error
2022

tests/ui/resolve/issue-109153.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use foo::*;
2+
3+
mod foo {
4+
pub mod bar {
5+
pub mod bar {
6+
pub mod bar {}
7+
}
8+
}
9+
}
10+
11+
use bar::bar; //~ ERROR `bar` is ambiguous
12+
use bar::*;
13+
14+
fn main() { }

tests/ui/resolve/issue-109153.stderr

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0659]: `bar` is ambiguous
2+
--> $DIR/issue-109153.rs:11:5
3+
|
4+
LL | use bar::bar;
5+
| ^^^ ambiguous name
6+
|
7+
= note: ambiguous because of multiple glob imports of a name in the same module
8+
note: `bar` could refer to the module imported here
9+
--> $DIR/issue-109153.rs:1:5
10+
|
11+
LL | use foo::*;
12+
| ^^^^^^
13+
= help: consider adding an explicit import of `bar` to disambiguate
14+
note: `bar` could also refer to the module imported here
15+
--> $DIR/issue-109153.rs:12:5
16+
|
17+
LL | use bar::*;
18+
| ^^^^^^
19+
= help: consider adding an explicit import of `bar` to disambiguate
20+
21+
error: aborting due to previous error
22+
23+
For more information about this error, try `rustc --explain E0659`.

0 commit comments

Comments
 (0)