Skip to content

Commit 376ff8b

Browse files
committed
fix(resolve): prevent infinite loop when glob-import self
1 parent e49122f commit 376ff8b

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

compiler/rustc_resolve/src/ident.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
10321032
Some(_) => continue,
10331033
None => return Err((Undetermined, Weak::Yes)),
10341034
};
1035+
1036+
if ptr::eq(module, glob_import.parent_scope.module) {
1037+
// do not glob-import a module into itself
1038+
continue;
1039+
}
1040+
10351041
let tmp_parent_scope;
10361042
let (mut adjusted_parent_scope, mut ident) =
10371043
(parent_scope, ident.normalize_to_macros_2_0());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use self::*;
2+
//~^ ERROR unresolved import `self::*`
3+
use crate::*;
4+
//~^ ERROR unresolved import `crate::*`
5+
use _::a;
6+
//~^ ERROR expected identifier, found reserved identifier `_`
7+
//~| ERROR unresolved import `_`
8+
use _::*;
9+
//~^ ERROR expected identifier, found reserved identifier `_`
10+
//~| ERROR unresolved import `_`
11+
12+
fn main() {
13+
use _::a;
14+
//~^ ERROR expected identifier, found reserved identifier `_`
15+
//~| ERROR unresolved import `_`
16+
use _::*;
17+
//~^ ERROR expected identifier, found reserved identifier `_`
18+
//~| ERROR unresolved import `_`
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
error: expected identifier, found reserved identifier `_`
2+
--> $DIR/issue-110164.rs:5:5
3+
|
4+
LL | use _::a;
5+
| ^ expected identifier, found reserved identifier
6+
7+
error: expected identifier, found reserved identifier `_`
8+
--> $DIR/issue-110164.rs:8:5
9+
|
10+
LL | use _::*;
11+
| ^ expected identifier, found reserved identifier
12+
13+
error: expected identifier, found reserved identifier `_`
14+
--> $DIR/issue-110164.rs:13:9
15+
|
16+
LL | use _::a;
17+
| ^ expected identifier, found reserved identifier
18+
19+
error: expected identifier, found reserved identifier `_`
20+
--> $DIR/issue-110164.rs:16:9
21+
|
22+
LL | use _::*;
23+
| ^ expected identifier, found reserved identifier
24+
25+
error[E0432]: unresolved import `self::*`
26+
--> $DIR/issue-110164.rs:1:5
27+
|
28+
LL | use self::*;
29+
| ^^^^^^^ cannot glob-import a module into itself
30+
31+
error[E0432]: unresolved import `crate::*`
32+
--> $DIR/issue-110164.rs:3:5
33+
|
34+
LL | use crate::*;
35+
| ^^^^^^^^ cannot glob-import a module into itself
36+
37+
error[E0432]: unresolved import `_`
38+
--> $DIR/issue-110164.rs:8:5
39+
|
40+
LL | use _::*;
41+
| ^ maybe a missing crate `_`?
42+
|
43+
= help: consider adding `extern crate _` to use the `_` crate
44+
45+
error[E0432]: unresolved import `_`
46+
--> $DIR/issue-110164.rs:5:5
47+
|
48+
LL | use _::a;
49+
| ^ maybe a missing crate `_`?
50+
|
51+
= help: consider adding `extern crate _` to use the `_` crate
52+
53+
error[E0432]: unresolved import `_`
54+
--> $DIR/issue-110164.rs:13:9
55+
|
56+
LL | use _::a;
57+
| ^ maybe a missing crate `_`?
58+
|
59+
= help: consider adding `extern crate _` to use the `_` crate
60+
61+
error[E0432]: unresolved import `_`
62+
--> $DIR/issue-110164.rs:16:9
63+
|
64+
LL | use _::*;
65+
| ^ maybe a missing crate `_`?
66+
|
67+
= help: consider adding `extern crate _` to use the `_` crate
68+
69+
error: aborting due to 10 previous errors
70+
71+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)