Skip to content

Commit a8153fa

Browse files
committed
fix(resolve): update the ambiguity glob binding recursively
1 parent fa06a37 commit a8153fa

11 files changed

+207
-4
lines changed

compiler/rustc_resolve/src/imports.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
321321
} else if !old_binding.vis.is_at_least(binding.vis, this.tcx) {
322322
// We are glob-importing the same item but with greater visibility.
323323
resolution.binding = Some(binding);
324+
} else if binding.is_ambiguity() {
325+
resolution.binding = Some(binding)
324326
}
325327
}
326328
(old_glob @ true, false) | (old_glob @ false, true) => {
@@ -393,7 +395,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
393395
let t = f(self, resolution);
394396

395397
match resolution.binding() {
396-
_ if old_binding.is_some() => return t,
397398
None => return t,
398399
Some(binding) => match old_binding {
399400
Some(old_binding) if ptr::eq(old_binding, binding) => return t,
@@ -402,7 +403,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
402403
}
403404
};
404405

405-
// Define `binding` in `module`s glob importers.
406+
// Define or update `binding` in `module`s glob importers.
406407
for import in module.glob_importers.borrow_mut().iter() {
407408
let mut ident = key.ident;
408409
let scope = match ident.span.reverse_glob_adjust(module.expansion, import.span) {

tests/ui/imports/duplicate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mod g {
3333
fn main() {
3434
e::foo();
3535
f::foo(); //~ ERROR `foo` is ambiguous
36-
g::foo();
36+
g::foo(); //~ ERROR `foo` is ambiguous
3737
}
3838

3939
mod ambiguous_module_errors {

tests/ui/imports/duplicate.stderr

+21-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ LL | pub use b::*;
4848
| ^^^^
4949
= help: consider adding an explicit import of `foo` to disambiguate
5050

51+
error[E0659]: `foo` is ambiguous
52+
--> $DIR/duplicate.rs:36:8
53+
|
54+
LL | g::foo();
55+
| ^^^ ambiguous name
56+
|
57+
= note: ambiguous because of multiple glob imports of a name in the same module
58+
note: `foo` could refer to the function imported here
59+
--> $DIR/duplicate.rs:24:13
60+
|
61+
LL | pub use a::*;
62+
| ^^^^
63+
= help: consider adding an explicit import of `foo` to disambiguate
64+
note: `foo` could also refer to the function imported here
65+
--> $DIR/duplicate.rs:25:13
66+
|
67+
LL | pub use b::*;
68+
| ^^^^
69+
= help: consider adding an explicit import of `foo` to disambiguate
70+
5171
error[E0659]: `foo` is ambiguous
5272
--> $DIR/duplicate.rs:49:9
5373
|
@@ -68,7 +88,7 @@ LL | use self::m2::*;
6888
| ^^^^^^^^^^^
6989
= help: consider adding an explicit import of `foo` to disambiguate
7090

71-
error: aborting due to 4 previous errors
91+
error: aborting due to 5 previous errors
7292

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

tests/ui/resolve/issue-105235.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// edition: 2021
2+
// check-pass
3+
4+
mod abc {
5+
pub struct Beeblebrox;
6+
pub struct Zaphod;
7+
}
8+
9+
mod foo {
10+
pub mod bar {
11+
use crate::abc::*;
12+
13+
#[derive(Debug)]
14+
pub enum Zaphod {
15+
Whale,
16+
President,
17+
}
18+
}
19+
pub use bar::*;
20+
}
21+
22+
mod baz {
23+
pub fn do_something() {
24+
println!("{:?}", crate::foo::Zaphod::Whale);
25+
}
26+
}
27+
28+
fn main() {
29+
baz::do_something();
30+
}

tests/ui/resolve/issue-112713.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// edition: 2021
2+
3+
pub fn foo() -> u32 {
4+
use sub::*;
5+
C //~ERROR `C` is ambiguous
6+
}
7+
8+
mod sub {
9+
mod mod1 { pub const C: u32 = 1; }
10+
mod mod2 { pub const C: u32 = 2; }
11+
12+
pub use mod1::*;
13+
pub use mod2::*;
14+
}
15+
16+
fn main() {}

tests/ui/resolve/issue-112713.stderr

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

tests/ui/resolve/issue-112743.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// https://github.com/rust-lang/rust/pull/112743#issuecomment-1601986883
2+
3+
macro_rules! m {
4+
() => {
5+
pub fn EVP_PKEY_id() {}
6+
};
7+
}
8+
9+
mod openssl {
10+
pub use self::evp::*;
11+
pub use self::handwritten::*;
12+
13+
mod evp {
14+
m!();
15+
}
16+
17+
mod handwritten {
18+
m!();
19+
}
20+
}
21+
use openssl::*;
22+
23+
fn main() {
24+
EVP_PKEY_id(); //~ ERROR `EVP_PKEY_id` is ambiguous
25+
}

tests/ui/resolve/issue-112743.stderr

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

tests/ui/resolve/issue-56593-0.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// check-pass
2+
3+
mod a {
4+
pub trait P {}
5+
}
6+
pub use a::*;
7+
8+
mod b {
9+
#[derive(Clone)]
10+
pub enum P {
11+
A
12+
}
13+
}
14+
pub use b::P;
15+
16+
mod c {
17+
use crate::*;
18+
pub struct S(Vec<P>);
19+
}
20+
21+
fn main() {}

tests/ui/resolve/issue-56593-1.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
3+
struct Foo;
4+
5+
mod foo {
6+
use super::*;
7+
8+
#[derive(Debug)]
9+
pub struct Foo;
10+
}
11+
12+
mod bar {
13+
use super::foo::*;
14+
15+
fn bar(_: Foo) {}
16+
}
17+
18+
fn main() {}

tests/ui/resolve/issue-56593-2.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// check-pass
2+
3+
use thing::*;
4+
5+
#[derive(Debug)]
6+
pub enum Thing {
7+
Foo,
8+
}
9+
10+
#[cfg(test)]
11+
mod tests {
12+
use super::*;
13+
14+
#[test]
15+
fn test_thing() {
16+
let thing = Thing::Foo;
17+
}
18+
}
19+
20+
mod thing {
21+
pub enum Thing {
22+
Bar,
23+
}
24+
}
25+
26+
fn main() {}

0 commit comments

Comments
 (0)