-
Notifications
You must be signed in to change notification settings - Fork 22
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
Implement (if-let) guards in pattern matchings #821
Conversation
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.
Thank you, the output looks like what we want!
However, we need:
- more tests (e.g. a match where more than one arm as an
if
/if let
, exerciseif
, exercise a non-trivialif let
with a computation in the RHS... you don't need to have the equivalent desugar for everything) - some description on the PR. Your PR should:
- explain the problem you solve (referring to an issue is fine, iff the issue has a nice and intelligible description about the exact problem we are solving, with examples --but in your case the issue has no description, please add some as requested in the issue)
- then give an overview of technically what is our approach
- then give examples of what one can do if your PR is merged (possibly with links to playground)
- note that those points above should basically be copy pastes from code documentations or tests cases
Thank you. I addressed most of your feedback but I can add more tests / documentation if you think it is not clear enough. |
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.
Thanks you, that's great! :)
I don't know how you want to do this optimization for "one wildcard arm" matches: in this PR or in a subsequent one?
I'll do it in this one |
@W95Psp That's done now |
Thanks, I think that's great now! Let's merge that PR :) |
Closes #814
This adds support for guards in pattern matchings. They are added to the AST (with a corresponding feature guard), and handled in the THIR import. A phase rewrites them as an equivalent nested pattern matching. Apart from supporting guards as specified in #807, this will also be useful for future phases that will generate guards (see #806).
Example of code with if-let guard (which is currently a nightly feature) and Rust code for the equivalent after the new phase:
Regular if guards are also supported (but for now desugared as if-let guards):