Skip to content

Commit 2c05214

Browse files
disallow ambiguous names imported from external crates
1 parent c607822 commit 2c05214

File tree

7 files changed

+48
-17
lines changed

7 files changed

+48
-17
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,8 +1645,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16451645

16461646
module.for_each_child(self, |this, ident, _, binding| {
16471647
let res = binding.res().expect_non_local();
1648-
let error_ambiguity = binding.is_ambiguity_recursive() && !binding.warn_ambiguity;
1649-
if res != def::Res::Err && !error_ambiguity {
1648+
if res != def::Res::Err && !binding.is_ambiguity_recursive() {
16501649
let mut reexport_chain = SmallVec::new();
16511650
let mut next_binding = binding;
16521651
while let NameBindingKind::Import { binding, import, .. } = next_binding.kind {

tests/ui/imports/ambiguous-2.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
//@ check-pass
21
//@ aux-build: ../ambiguous-1.rs
32
// https://github.com/rust-lang/rust/pull/113099#issuecomment-1633574396
43

54
extern crate ambiguous_1;
65

76
fn main() {
8-
ambiguous_1::id();
7+
ambiguous_1::id(); //~ ERROR cannot find function `id` in crate `ambiguous_1`
98
//^ FIXME: `id` should be identified as an ambiguous item.
109
}

tests/ui/imports/ambiguous-2.stderr

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0425]: cannot find function `id` in crate `ambiguous_1`
2+
--> $DIR/ambiguous-2.rs:7:18
3+
|
4+
LL | ambiguous_1::id();
5+
| ^^ not found in `ambiguous_1`
6+
|
7+
help: consider importing this function
8+
|
9+
LL + use std::process::id;
10+
|
11+
help: if you import `id`, refer to it directly
12+
|
13+
LL - ambiguous_1::id();
14+
LL + id();
15+
|
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0425`.

tests/ui/imports/ambiguous-4.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
//@ check-pass
21
//@ aux-build: ../ambiguous-4-extern.rs
32

43
extern crate ambiguous_4_extern;
54

65
fn main() {
7-
ambiguous_4_extern::id();
6+
ambiguous_4_extern::id(); //~ ERROR cannot find function `id` in crate `ambiguous_4_extern`
87
//^ FIXME: `id` should be identified as an ambiguous item.
98
}

tests/ui/imports/ambiguous-4.stderr

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0425]: cannot find function `id` in crate `ambiguous_4_extern`
2+
--> $DIR/ambiguous-4.rs:6:25
3+
|
4+
LL | ambiguous_4_extern::id();
5+
| ^^ not found in `ambiguous_4_extern`
6+
|
7+
help: consider importing this function
8+
|
9+
LL + use std::process::id;
10+
|
11+
help: if you import `id`, refer to it directly
12+
|
13+
LL - ambiguous_4_extern::id();
14+
LL + id();
15+
|
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0425`.

tests/ui/imports/glob-conflict-cross-crate-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() {
66
glob_conflict::f(); //~ ERROR cannot find function `f` in crate `glob_conflict`
77
//^ FIXME: `glob_conflict::f` should raise an
88
// ambiguity error instead of a not found error.
9-
glob_conflict::glob::f();
9+
glob_conflict::glob::f(); //~ ERROR cannot find function `f` in module `glob_conflict::glob`
1010
//^ FIXME: `glob_conflict::glob::f` should raise an
1111
// ambiguity error instead of a not found error.
1212
}

tests/ui/imports/glob-conflict-cross-crate-1.stderr

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ error[E0425]: cannot find function `f` in crate `glob_conflict`
33
|
44
LL | glob_conflict::f();
55
| ^ not found in `glob_conflict`
6+
7+
error[E0425]: cannot find function `f` in module `glob_conflict::glob`
8+
--> $DIR/glob-conflict-cross-crate-1.rs:9:26
69
|
7-
help: consider importing this function
8-
|
9-
LL + use glob_conflict::glob::f;
10-
|
11-
help: if you import `f`, refer to it directly
12-
|
13-
LL - glob_conflict::f();
14-
LL + f();
15-
|
10+
LL | glob_conflict::glob::f();
11+
| ^ not found in `glob_conflict::glob`
1612

17-
error: aborting due to 1 previous error
13+
error: aborting due to 2 previous errors
1814

1915
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)