Skip to content

Commit 924b911

Browse files
Rollup merge of rust-lang#153912 - mu001999-contrib:fix-153842, r=petrochenkov
Avoid prematurely choosing a glob import Fixes rust-lang#153842 Use the following without introducing trait to explain: ```rust mod a { pub use crate::x::y as x; // single import #1 } mod b { pub mod x { pub mod y {} } } use a::x; // single import rust-lang#2 use b::*; // glob import rust-lang#3 fn main() {} ``` In current implementation, when `#1` is first resolved, `crate::x` is temporarily taken from glob import `rust-lang#3` as `crate::b::x`. This happens because `single_import_can_define_name` will see that `rust-lang#2` cannot define `x` (because it depends on `#1` and `#1` is ignored) and then return `false`. Later, during finalization, `crate::x` in `#1` resolves through single import `rust-lang#2` instead, which no longer matches the initially cached module `crate::b::x` and triggers the ICE. I think the resolver should keep this unresolved because `rust-lang#2` may still define `x` to avoid prematurely choosing a glob import. r? petrochenkov
2 parents 7011667 + 5316bab commit 924b911

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

compiler/rustc_resolve/src/ident.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
13731373
&single_import.parent_scope,
13741374
None,
13751375
ignore_decl,
1376-
ignore_import,
1376+
None,
13771377
) {
13781378
Err(Determined) => continue,
13791379
Ok(binding)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
mod a {
2+
pub use crate::s::Trait as s;
3+
//~^ ERROR cannot determine resolution for the import
4+
//~| ERROR cannot determine resolution for the import
5+
//~| ERROR unresolved imports `crate::s::Trait`, `a::s`
6+
}
7+
8+
mod b {
9+
pub mod s {
10+
pub trait Trait {}
11+
}
12+
}
13+
14+
use a::s;
15+
use b::*;
16+
17+
fn main() {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: cannot determine resolution for the import
2+
--> $DIR/inconsistent-resolution-153842.rs:2:13
3+
|
4+
LL | pub use crate::s::Trait as s;
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
7+
error: cannot determine resolution for the import
8+
--> $DIR/inconsistent-resolution-153842.rs:2:13
9+
|
10+
LL | pub use crate::s::Trait as s;
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
|
13+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14+
15+
error[E0432]: unresolved imports `crate::s::Trait`, `a::s`
16+
--> $DIR/inconsistent-resolution-153842.rs:2:13
17+
|
18+
LL | pub use crate::s::Trait as s;
19+
| ^^^^^^^^^^^^^^^^^^^^
20+
...
21+
LL | use a::s;
22+
| ^^^^
23+
24+
error: aborting due to 3 previous errors
25+
26+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)