-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Support negative numbers in Literal::from_str #87262
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
r? @Aaron1011 Do you want to take this? |
test_parse_literal(); | ||
} | ||
|
||
fn test_display_literal() { | ||
assert_eq!(Literal::isize_unsuffixed(-10).to_string(), "- 10"); |
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.
This looks like a pre-existing bug - this literal will not round-trip, since "- 10" will result in a parse error. Could you open an issue for this?
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.
It's fixed in #87267.
Sorry for the delay in getting to this. @bors r+ |
📌 Commit 55ff45a has been approved by |
☀️ Test successful - checks-actions |
proc_macro::Literal has allowed negative numbers in a single literal token ever since Rust 1.29, using https://doc.rust-lang.org/stable/proc_macro/struct.Literal.html#method.isize_unsuffixed and similar constructors.
However, the suite of constructors on Literal is not sufficient for all use cases, for example arbitrary precision floats, or custom suffixes in FFI macros.
For those, macros construct the literal using from_str instead, which preserves arbitrary precision, custom suffixes, base, and digit grouping.
However, until this PR it was not possible to construct a literal token that is both negative and preserving of arbitrary precision etc.
This PR fixes
Literal::from_str
to recognize negative integer and float literals.