-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(resolve): prevent infinite loop when glob-import self #110264
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use self::*; | ||
//~^ ERROR unresolved import `self::*` | ||
use crate::*; | ||
//~^ ERROR unresolved import `crate::*` | ||
use _::a; | ||
//~^ ERROR expected identifier, found reserved identifier `_` | ||
//~| ERROR unresolved import `_` | ||
use _::*; | ||
//~^ ERROR expected identifier, found reserved identifier `_` | ||
//~| ERROR unresolved import `_` | ||
|
||
fn main() { | ||
use _::a; | ||
//~^ ERROR expected identifier, found reserved identifier `_` | ||
//~| ERROR unresolved import `_` | ||
use _::*; | ||
//~^ ERROR expected identifier, found reserved identifier `_` | ||
//~| ERROR unresolved import `_` | ||
} |
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,71 @@ | ||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/issue-110164.rs:5:5 | ||
| | ||
LL | use _::a; | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/issue-110164.rs:8:5 | ||
| | ||
LL | use _::*; | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/issue-110164.rs:13:9 | ||
| | ||
LL | use _::a; | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error: expected identifier, found reserved identifier `_` | ||
--> $DIR/issue-110164.rs:16:9 | ||
| | ||
LL | use _::*; | ||
| ^ expected identifier, found reserved identifier | ||
|
||
error[E0432]: unresolved import `self::*` | ||
--> $DIR/issue-110164.rs:1:5 | ||
| | ||
LL | use self::*; | ||
| ^^^^^^^ cannot glob-import a module into itself | ||
|
||
error[E0432]: unresolved import `crate::*` | ||
--> $DIR/issue-110164.rs:3:5 | ||
| | ||
LL | use crate::*; | ||
| ^^^^^^^^ cannot glob-import a module into itself | ||
|
||
error[E0432]: unresolved import `_` | ||
--> $DIR/issue-110164.rs:8:5 | ||
| | ||
LL | use _::*; | ||
| ^ maybe a missing crate `_`? | ||
| | ||
= help: consider adding `extern crate _` to use the `_` crate | ||
|
||
error[E0432]: unresolved import `_` | ||
--> $DIR/issue-110164.rs:5:5 | ||
| | ||
LL | use _::a; | ||
| ^ maybe a missing crate `_`? | ||
| | ||
= help: consider adding `extern crate _` to use the `_` crate | ||
|
||
error[E0432]: unresolved import `_` | ||
--> $DIR/issue-110164.rs:13:9 | ||
| | ||
LL | use _::a; | ||
| ^ maybe a missing crate `_`? | ||
| | ||
= help: consider adding `extern crate _` to use the `_` crate | ||
|
||
error[E0432]: unresolved import `_` | ||
--> $DIR/issue-110164.rs:16:9 | ||
| | ||
LL | use _::*; | ||
| ^ maybe a missing crate `_`? | ||
| | ||
= help: consider adding `extern crate _` to use the `_` crate | ||
|
||
error: aborting due to 10 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0432`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does
use _::*
trigger the "glob-import a module into itself" in the first place?I'd expect
_
to resolve intoRes::Err
here.Is it possible to reproduce the ICE without
_::*
, just with regular well-formed imports?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will not occur, other cases will hit map_err
When executing new_key, special processing is performed for
_
to ensure that_
each time thekey
is not the same, it is intended to solve the case ofxxx as _
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, fascinating.
The
underscore_disambiguator += 1
should only apply when we define names, not when we are retrieving already added definitions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding
BindingKey::new
method that will be used everywhere by default, and renamenew_key
tonew_disambiguated_key
and use it only when addinguse foo as _
imports to a module (infn add_import
I guess, but I'm not sure).Note that if
new_key
is called for a single import twice in different contexts, then the resulting disambiguators are not consistent with each other, and it's something that is suspicious at least.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is independent from glob imports and we should do it first.
The glob change also looks reasonable, maybe it fixes some other actual issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I will open a new PR to rewrite
new_key
, what do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, new PR.