-
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
Add expr202x
macro pattern
#84364
Add expr202x
macro pattern
#84364
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
cc @rust-lang/project-edition-2021 |
Hmm, I'm in favor of the concept overall, but I'd like to have a bit of a "write-up" or something that brings together the required information. I don't quite remember, for example, what changes were required to the |
Alright, that's entirely understandable! So it looks like the back compat thing for let chaining came from this comment discussion: #60861 (comment) and an associated fixme in the feature gate ui test introduced by that pr which passes here because this pr doesn't inflict the new behaviour on any edition yet. In other words, this one is here because of conservatism. But we can probably assume that someone out there has written a macro that depends on the exception in the current expression behaviour based on the next one's experience: The other exception for inline const was because we got bitten by the issue that was proposed in the above discussion, but in the context of inline const. This exception got in because of #80135: it was needed to keep some macros on beta working, which expected the const keyword then some expression after, as I understand it based on my testing and reading examples. The former exception was removed here since I was bifurcating anyway and could reserve it. The latter was because of inline const needing to have parens around it to be valid in macro invocations currently, which is odd and rather confusing (I didn't know about this trick to get it accepted by the parser until it was pointed out to me by a friend so I assumed it simply wasn't allowed. the error here is bad too). Macros taking Does this need to happen now? Not strictly. It could happen later or never, at the expense of macros being a little more confusing: This PR was written while I was under the invalid impression you couldn't pass a const block to a macro as an expression, which I now know is possible with parens, but that fact was anything but discoverable. It would be good to resolve the syntax ambiguity to favour consistency in being able to put |
I see. So the |
Nominated for @rust-lang/lang discussion. |
☔ The latest upstream changes (presumably #84310) made this pull request unmergeable. Please resolve the merge conflicts. |
This makes it possible to use `inline_const` (rust-lang#76001) and `let_chains` (rust-lang#53667) inside macros' `expr` patterns in a future edition by bifurcating the `expr` nonterminal in a similar way to `pat2021` to remove some backwards compatibility exceptions that disallow `const`/`let` at the beginning of an `expr` match. Fixes rust-lang#84155 and relaxes the backward compat restriction from rust-lang#80135 for a future edition. This is not intended to go into 2021 as it I don't think it's simple to write an automatic fix, and certainly not now that it's past the soft deadline for inclusion in 2021 by a long shot. Here is a pathological case of rust-lang#79908 that forces this to be an edition change: ```rust macro_rules! evil { ($e:expr) => { // or something else const {$e-1} }; (const $b:block) => { const {$b} } } fn main() { let x = 5; match x { evil!(const { 5 }) => panic!("oh no"), _ => (), }; } ```
force push: Fixed the merge conflict and also the feature gate using the wrong suggestion |
☔ The latest upstream changes (presumably #83386) made this pull request unmergeable. Please resolve the merge conflicts. |
I believe the conclusion of the lang team is that we are not confident that the approach used in this PR is the exact right one we want to deploy, and so I propose we close this PR while we wait to resolve the questions raised in #86730. |
@rfcbot close |
Team member @pnkfelix has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@rfcbot reviewed |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
Closing according to the fcp decision above. |
as noted by @traviscross elsewhere: Further action here is now gated on acceptance of rust-lang/rfcs#3531, "Macro matcher fragment specifiers edition policy". |
That RFC has been accepted, so if someone wants to make progress here, you can help by picking up this PR, making sure it matches the RFC, and making it work with today's compiler. :) |
This makes it possible to use
inline_const
(#76001) andlet_chains
(#53667) inside macros'
expr
patterns in a future edition bybifurcating the
expr
nonterminal in a similar way topat2021
toremove some backwards compatibility exceptions that disallow
const
/let
at the beginning of anexpr
match.Fixes #84155 and relaxes the backward compat restriction from #80135 for
a future edition. This is not necessarily intended to go into 2021 as it I don't
think it's simple to write an automatic fix, and I definitely won't have time very
soon.
Here is a pathological case of #79908 that forces this to be an edition
change: