mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #153912 - mu001999-contrib:fix-153842, r=petrochenkov
Avoid prematurely choosing a glob import
Fixes rust-lang/rust#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 #2
use b::*; // glob import #3
fn main() {}
```
In current implementation, when `#1` is first resolved, `crate::x` is temporarily taken from glob import `#3` as `crate::b::x`. This happens because `single_import_can_define_name` will see that `#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 `#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 `#2` may still define `x` to avoid prematurely choosing a glob import.
r? petrochenkov
This commit is contained in:
@@ -1373,7 +1373,7 @@ fn single_import_can_define_name<'r>(
|
||||
&single_import.parent_scope,
|
||||
None,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
None,
|
||||
) {
|
||||
Err(Determined) => continue,
|
||||
Ok(binding)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
mod a {
|
||||
pub use crate::s::Trait as s;
|
||||
//~^ ERROR cannot determine resolution for the import
|
||||
//~| ERROR cannot determine resolution for the import
|
||||
//~| ERROR unresolved imports `crate::s::Trait`, `a::s`
|
||||
}
|
||||
|
||||
mod b {
|
||||
pub mod s {
|
||||
pub trait Trait {}
|
||||
}
|
||||
}
|
||||
|
||||
use a::s;
|
||||
use b::*;
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,26 @@
|
||||
error: cannot determine resolution for the import
|
||||
--> $DIR/inconsistent-resolution-153842.rs:2:13
|
||||
|
|
||||
LL | pub use crate::s::Trait as s;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: cannot determine resolution for the import
|
||||
--> $DIR/inconsistent-resolution-153842.rs:2:13
|
||||
|
|
||||
LL | pub use crate::s::Trait as s;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error[E0432]: unresolved imports `crate::s::Trait`, `a::s`
|
||||
--> $DIR/inconsistent-resolution-153842.rs:2:13
|
||||
|
|
||||
LL | pub use crate::s::Trait as s;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | use a::s;
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0432`.
|
||||
Reference in New Issue
Block a user