forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#124840 - bvanjoi:fix-124490, r=petrochenkov
resolve: mark it undetermined if single import is not has any bindings - Fixes rust-lang#124490 - Fixes rust-lang#125013 This issue arises from incorrect resolution updates, for example: ```rust mod a { pub mod b { pub mod c {} } } use a::*; use b::c; use c as b; fn main() {} ``` 1. In the first loop, binding `(root, b)` is refer to `root::a::b` due to `use a::*`. 1. However, binding `(root, c)` isn't defined by `use b::c` during this stage because `use c as b` falls under the `single_imports` of `(root, b)`, where the `imported_module` hasn't been computed yet. This results in marking the `path_res` for `b` as `Indeterminate`. 2. Then, the `imported_module` for `use c as b` will be recorded. 2. In the second loop, `use b::c` will be processed again: 1. Firstly, it attempts to find the `path_res` for `(root, b)`. 2. It will iterate through the `single_imports` of `use b::c`, encounter `use c as b`, attempt to resolve `c` in `root`, and ultimately return `Err(Undetermined)`, thus passing the iterator. 3. Use the binding `(root, b)` -> `root::a::b` introduced by `use a::*` and ultimately return `root::a::b` as the `path_res` of `b`. 4. Then define the binding `(root, c)` -> `root::a::b::c`. 3. Then process `use c as b`, update the resolution for `(root, b)` to refer to `root::a::b::c`, ultimately causing inconsistency. In my view, step `2.2` has an issue where it should exit early, similar to the behavior when there's no `imported_module`. Therefore, I've added an attribute called `indeterminate` to `ImportData`. This will help us handle only those single imports that have at least one determined binding. r? `@petrochenkov`
- Loading branch information
Showing
11 changed files
with
142 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//@ check-pass | ||
|
||
// https://github.com/rust-lang/rust/pull/124840#issuecomment-2098148587 | ||
|
||
mod a { | ||
pub(crate) use crate::S; | ||
} | ||
mod b { | ||
pub struct S; | ||
} | ||
use self::a::S; | ||
use self::b::*; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//@ check-pass | ||
|
||
// similar `cycle-import-in-diff-module-0.rs` | ||
|
||
mod a { | ||
pub(crate) use crate::s; | ||
} | ||
mod b { | ||
pub mod s {} | ||
} | ||
use self::b::*; | ||
use self::a::s; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// https://github.com/rust-lang/rust/issues/124490 | ||
|
||
mod a { | ||
pub mod b { | ||
pub mod c {} | ||
} | ||
} | ||
|
||
use a::*; | ||
|
||
use b::c; | ||
//~^ ERROR: cannot determine resolution for the import | ||
//~| ERROR: cannot determine resolution for the import | ||
//~| ERROR: unresolved import `b::c` | ||
use c as b; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error: cannot determine resolution for the import | ||
--> $DIR/shadow-glob-module-resolution-1.rs:11:5 | ||
| | ||
LL | use b::c; | ||
| ^^^^ | ||
|
||
error: cannot determine resolution for the import | ||
--> $DIR/shadow-glob-module-resolution-1.rs:11:5 | ||
| | ||
LL | use b::c; | ||
| ^^^^ | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error[E0432]: unresolved import `b::c` | ||
--> $DIR/shadow-glob-module-resolution-1.rs:11:5 | ||
| | ||
LL | use b::c; | ||
| ^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0432`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// https://github.com/rust-lang/rust/issues/125013 | ||
|
||
mod a { | ||
pub mod b { | ||
pub mod c { | ||
pub trait D {} | ||
} | ||
} | ||
} | ||
|
||
use a::*; | ||
|
||
use e as b; | ||
//~^ ERROR: unresolved import `e` | ||
use b::c::D as e; | ||
//~^ ERROR: cannot determine resolution for the import | ||
//~| ERROR: cannot determine resolution for the import | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error: cannot determine resolution for the import | ||
--> $DIR/shadow-glob-module-resolution-2.rs:15:5 | ||
| | ||
LL | use b::c::D as e; | ||
| ^^^^^^^^^^^^ | ||
|
||
error: cannot determine resolution for the import | ||
--> $DIR/shadow-glob-module-resolution-2.rs:15:5 | ||
| | ||
LL | use b::c::D as e; | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error[E0432]: unresolved import `e` | ||
--> $DIR/shadow-glob-module-resolution-2.rs:13:5 | ||
| | ||
LL | use e as b; | ||
| -^^^^^ | ||
| | | ||
| no `e` in the root | ||
| help: a similar name exists in the module: `a` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0432`. |