Support negative numbers in Literal::from_str#87262
Merged
bors merged 1 commit intorust-lang:masterfrom Aug 3, 2021
Merged
Conversation
Contributor
|
(rust-highfive has picked a reviewer for you, use r? to override) |
Contributor
|
r? @Aaron1011 Do you want to take this? |
Aaron1011
reviewed
Aug 3, 2021
| } | ||
|
|
||
| fn test_display_literal() { | ||
| assert_eq!(Literal::isize_unsuffixed(-10).to_string(), "- 10"); |
Contributor
There was a problem hiding this comment.
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?
Contributor
|
Sorry for the delay in getting to this. @bors r+ |
Collaborator
|
📌 Commit 55ff45a has been approved by |
Collaborator
Collaborator
|
☀️ Test successful - checks-actions |
This was referenced Oct 26, 2021
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.
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_strto recognize negative integer and float literals.