-
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 edition for pat
fragments
#84452
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
The current behavior is correct, |
@petrochenkov The current behavior is that |
After a more detailed look I see what is the issue. So the correct edition is lost somewhere on the way from decoding (or even encoding) the macro to parsing its left hand side as tokens. This PR replaces a per-token edition check with a global edition check, which happens to work in this specific case, but isn't really correct. |
Tokens decoded by UPD: Before being encoded in UPD: I don't have time to investigate this further today. |
Yes, good point, I just found that too. Thanks.
Does that mean |
Yes, something like // One edition
macro pass(item:$item) { $item }
// Another edition
pass! {
macro matches(... $pat: pat | ...) { ... }
} should work as a test. |
It turns out that we've been decoding editions incorrectly for root rust/compiler/rustc_span/src/hygiene.rs Lines 1060 to 1065 in 58bdb08
This will decode an I'll work on a fix. |
One tricky aspect to this is that there are many places where we compare I'm not sure if this will create any problems, especially around some of the macros-2.0 logic. |
Ah, this is the reason. Some code working on |
@petrochenkov: So, the idea would be that we have multiple 'roots':
|
Yes. |
If |
I personally don't think it is high enough priority to add some kind of exception right away. The only people testing 2021 are compiler developers, and I don't think this is necessarily blocking anyone right this moment. If this can be fixed within a few weeks, I think that should be sufficient timing-wise. Testing was supposed to start mid-may, but the schedule has slipped quite a bit. Also, this affects anyone doing a similar style (for example, this macro in cssparser). Although |
I think I can close this PR now? |
Is there an issue to track the fixup work here? |
I guess it is #84429 |
The edition
span.edition()
returned seems wrong (at least it'sEdition2021
in the example of #84429) -- the correct one seems to be provided by theedition
parameter ofrustc_expand::mbe::macro_rules::compile_declarative_macro()
.Fixes #84429.