Skip to content
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

Use correct edition when parsing :pat matchers #85709

Merged
merged 1 commit into from
May 30, 2021

Conversation

Aaron1011
Copy link
Member

As described in issue #85708, we currently do not properly decode
SyntaxContext::root() and ExpnId::root() from foreign crates. As a
result, when we decode a span from a foreign crate with
SyntaxContext::root(), we end up up considering it to have the edition
of the current crate, instead of the foreign crate where it was
originally created.

A full fix for this issue will be a fairly significant undertaking.
Fortunately, it's possible to implement a partial fix, which gives us
the correct edition-dependent behavior for :pat matchers when the
macro is loaded from another crate. Since we have the edition of the
macro's defining crate available, we can 'recover' from seeing a
SyntaxContext::root() and use the edition of the macro's defining
crate.

Any solution to issue #85708 must reproduce the behavior of this
targeted fix - properly preserving a foreign SyntaxContext::root()
means (among other things) preserving its edition, which by definition
is the edition of the foreign crate itself. Therefore, this fix moves us
closer to the correct overall solution, and does not expose any new
incorrect behavior to macros.

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 26, 2021
@petrochenkov
Copy link
Contributor

r? @petrochenkov

@m-ou-se m-ou-se linked an issue May 27, 2021 that may be closed by this pull request
@petrochenkov
Copy link
Contributor

r=me with the typo (#85709 (comment)) fixed.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 29, 2021
As described in issue rust-lang#85708, we currently do not properly decode
`SyntaxContext::root()` and `ExpnId::root()` from foreign crates. As a
result, when we decode a span from a foreign crate with
`SyntaxContext::root()`, we end up up considering it to have the edition
of the *current* crate, instead of the foreign crate where it was
originally created.

A full fix for this issue will be a fairly significant undertaking.
Fortunately, it's possible to implement a partial fix, which gives us
the correct edition-dependent behavior for `:pat` matchers when the
macro is loaded from another crate. Since we have the edition of the
macro's defining crate available, we can 'recover' from seeing a
`SyntaxContext::root()` and use the edition of the macro's defining
crate.

Any solution to issue rust-lang#85708 must reproduce the behavior of this
targeted fix - properly preserving a foreign `SyntaxContext::root()`
means (among other things) preserving its edition, which by definition
is the edition of the foreign crate itself. Therefore, this fix moves us
closer to the correct overall solution, and does not expose any new
incorrect behavior to macros.
@Aaron1011 Aaron1011 force-pushed the fix-pat-crate-edition branch from 7241d3b to d874ecc Compare May 29, 2021 18:09
@Aaron1011
Copy link
Member Author

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented May 29, 2021

📌 Commit d874ecc has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 29, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request May 30, 2021
…petrochenkov

Use correct edition when parsing `:pat` matchers

As described in issue rust-lang#85708, we currently do not properly decode
`SyntaxContext::root()` and `ExpnId::root()` from foreign crates. As a
result, when we decode a span from a foreign crate with
`SyntaxContext::root()`, we end up up considering it to have the edition
of the *current* crate, instead of the foreign crate where it was
originally created.

A full fix for this issue will be a fairly significant undertaking.
Fortunately, it's possible to implement a partial fix, which gives us
the correct edition-dependent behavior for `:pat` matchers when the
macro is loaded from another crate. Since we have the edition of the
macro's defining crate available, we can 'recover' from seeing a
`SyntaxContext::root()` and use the edition of the macro's defining
crate.

Any solution to issue rust-lang#85708 must reproduce the behavior of this
targeted fix - properly preserving a foreign `SyntaxContext::root()`
means (among other things) preserving its edition, which by definition
is the edition of the foreign crate itself. Therefore, this fix moves us
closer to the correct overall solution, and does not expose any new
incorrect behavior to macros.
bors added a commit to rust-lang-ci/rust that referenced this pull request May 30, 2021
…laumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#85285 (Add eslint checks to CI)
 - rust-lang#85709 (Use correct edition when parsing `:pat` matchers)
 - rust-lang#85762 (Do not try to build LLVM with Zlib on Windows)
 - rust-lang#85770 (Remove `--print unversioned-files` from rustdoc )
 - rust-lang#85781 (Add documentation for aarch64-apple-ios-sim target)
 - rust-lang#85801 (Add `String::extend_from_within`)
 - rust-lang#85817 (Fix a typo)
 - rust-lang#85818 (Don't drop `PResult` without handling the error)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit bdd7062 into rust-lang:master May 30, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 30, 2021
@m-ou-se
Copy link
Member

m-ou-se commented May 31, 2021

Thank you for fixing this, @Aaron1011!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

matches! problem with edition 2021
7 participants