-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[RFC-2011] Expand matches!
#110382
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
Closed
Closed
[RFC-2011] Expand matches!
#110382
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
@est31 Someway, somehow it is necessary to have an indicator pointing to the scrutinee expression of
matches!
in order to capture its content and the use of regular declarative macros makesmatches!
in this context a opaqueExprKind::MacCall
which can't be captured without further processing. In regards to macro 2.0, I personally don't know how it can help here.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.
Hmm yeah then I have misunderstood and this PR is not an use case for
builtin #
really. I'm sorry for having suggested it earlier.Your PR currently hardcodes the
matches!
macro, meaning that it can't be shadowed or used via a different name. The same is true foroffset_of!
which currently isn't part of the prelude, and which is also unstable, but this PR exposes it without feature gating. Also the builtin equivalent of offset_of is not meant to be used directly as it doesnt have as good error reporting or recovery (and it tolerates some things that are caught one layer higher by the macro_rules macro).So this is not an approach that reviewers will merge I think.
If you want to do hardcoding, you could confine it at least to what happens inside the
assert!()
call and just check the path of theMacCall
and if it only has one item and that one ismatches
, then processing the content. This would also not work via shadowing and use with a different name, but would be only confined to uses insideassert!()
, not everywhere, and would not touchoffset_of
. It would also not need a new AST item which should still be added sparingly.That would not be perfect but many times better than what there is now in this PR.
If you want to be a bit more advanced you could maybe try to resolve the macro first, then check if it is the same
SyntaxExtension
as the one of a pre-storedmatches
syntax extension.The correct way of using
builtin #
here is to both turnmatches
andassert
intobuiltin #
constructs, but personally I'm more of a fan of re-parsing the same info multiple times.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 @est31
Hum... Looks like a way forward is unclear, three different approaches were already presented (including adhoc processing inside
assert
as you commented) without much apparent success.To avoid further back-and-forth, I think it is better to wait for @petrochenkov. Personally, I am happy with any strategy as long as
matches!
are expanded :)I hadn't thought that, looks promising!