-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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): not defined extern crate shadow_name
#111761
Merged
Merged
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
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,15 @@ | ||
// edition: 2021 | ||
|
||
// https://github.com/rust-lang/rust/pull/111761#issuecomment-1557777314 | ||
macro_rules! m { | ||
() => { | ||
extern crate core as std; | ||
//~^ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern` | ||
} | ||
} | ||
|
||
m!(); | ||
|
||
use std::mem; | ||
|
||
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,13 @@ | ||
error: macro-expanded `extern crate` items cannot shadow names passed with `--extern` | ||
--> $DIR/issue-109148.rs:6:9 | ||
| | ||
LL | extern crate core as std; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | m!(); | ||
| ---- in this macro invocation | ||
| | ||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to previous error | ||
|
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.
Yeah, this is a good solution too.
Could you add a comment saying that this is an ambiguity error, but it's not registered in
ambiguity_errors
, and that triggers some asserts later on if the binding is added, so we don't add the binding.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 think it's worth discussing the actual binding of
use std::xxx
.When we add
return
here,std::xxx
ultimately refers toprelude::std
.However, based on your comment, it seems that
std::xxx
will point toextern crate blash
(I guess, but not entirely sure).There might be a difference between these two resolutions, so in my opinion, we should determine which action is better first.
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.
The choice is not that important because it only happens during failing compilation anyway.
The difference may only happen in some secondary diagnostics.
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.
If this case is migrated to regular ambiguity errors, then
extern crate blah
will be selected as a resolution, yes, because it's closer in scopes at the resolution point.(This migration is probably a better long term solution, but it's a minor language change, so it's better done separately from fixing an ICE.)
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.
If the migration to regular ambiguity errors happens then this test case:
won't produce any errors.