Store NtLiteral without generalizing to Expr#92392
Closed
dtolnay wants to merge 1 commit intorust-lang:masterfrom
Closed
Store NtLiteral without generalizing to Expr#92392dtolnay wants to merge 1 commit intorust-lang:masterfrom
dtolnay wants to merge 1 commit intorust-lang:masterfrom
Conversation
Contributor
|
r? @davidtwco (rust-highfive has picked a reviewer for you, use r? to override) |
Contributor
petrochenkov
reviewed
Jan 1, 2022
Contributor
petrochenkov
left a comment
There was a problem hiding this comment.
I want to check some things before proceeding with changes in this area, cc #92472.
Contributor
|
Some random thoughts:
|
Member
Author
|
Thanks for the review! I can tell I'm not going to change your mind on this so I'll go ahead and close. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The discussion under #91166 raised the question of whether a NtLiteral (the value of a
$:literalmatcher in macro_rules) can be conceptualized as a single token, the way that$:identis. Today it isn't — a negative literal is passed to procedural macros as a pair of proc macro tokens:However proc macro literals already support negative literals in a single token, and it's easy to construct one:
proc_macro::Literal::i32_unsuffixed(-1). As such, given that macro_rules's$:literaland proc_macro::Literal are both already capable of representing negative literals in one piece, I think having those literals fall apart on entry into the proc macro is not a great behavior. My expectation would be that the proc macro call in the snippet above would pass a single token which is equivalent toproc_macro::Literal::i32_unsuffixed(-1), and I'd like to start making changes in that direction.This PR does not make any intentional observable behavior change, but it replaces the way that
$:literalis represented internally fromP<Expr>(which happens to be always eitherExprKind::LitorExprKind::Unary(UnOp::Neg, ExprKind::Lit)if rustc is correctly implemented) to a dedicatedSignedLiteraltype. This makes illegal states unrepresentable and will make it more straightforward to map$:literalone-to-one to proc_macro::Literal whenever that comes up.