Skip to content

Add _value API for number literals in proc-macro#154608

Open
GuillaumeGomez wants to merge 2 commits intorust-lang:mainfrom
GuillaumeGomez:number_value_proc-macro_API
Open

Add _value API for number literals in proc-macro#154608
GuillaumeGomez wants to merge 2 commits intorust-lang:mainfrom
GuillaumeGomez:number_value_proc-macro_API

Conversation

@GuillaumeGomez
Copy link
Copy Markdown
Member

@GuillaumeGomez GuillaumeGomez commented Mar 30, 2026

Part of #136652.

This PR adds the *_value for numbers (integers and floats). However, f16 and f128 are voluntarily left out as they're still unstable. Adding support for them is just a matter of uncommenting two lines, so should be fine.

Setting same reviewer as last time.

r? @Urgau

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 30, 2026
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the number_value_proc-macro_API branch from ae03536 to 7cb03fd Compare March 31, 2026 09:53
@GuillaumeGomez
Copy link
Copy Markdown
Member Author

My favourite kind of failure: works locally but not in CI. T_T

Updated the value in the tests to see which one exactly is failing.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the number_value_proc-macro_API branch from 7cb03fd to c755b56 Compare March 31, 2026 13:14
@GuillaumeGomez
Copy link
Copy Markdown
Member Author

Bug comes from an issue with GCC proc-macro ABI. Ignoring this test on GCC backend for now.

@GuillaumeGomez
Copy link
Copy Markdown
Member Author

CI fixed. :)

@Urgau
Copy link
Copy Markdown
Member

Urgau commented Mar 31, 2026

A libs (or maybe even libs-api) reviewer seems more appropriate to review this PR.

r? Amanieu (since you reviewed #136355)

@rustbot rustbot assigned Amanieu and unassigned Urgau Mar 31, 2026
@Urgau
Copy link
Copy Markdown
Member

Urgau commented Mar 31, 2026

I missed it already has an accepted ACP. The PR can be reviewed by libs reviewer.

r? libs

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Mar 31, 2026
@rustbot rustbot assigned Mark-Simulacrum and unassigned Amanieu Mar 31, 2026
Hexadecimal = 16,
}

fn parse_number(value: &str) -> (String, Base) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this exactly in sync with what the rustc parser permits?

I guess that would be a mix of https://doc.rust-lang.org/nightly/reference/tokens.html#grammar-INTEGER_LITERAL and whatever we then tokenize from it?

Perhaps this should go over the bridge and ask rustc to parse the string for us?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no code in rustc currently which would allow this conversion without including a lot of other things. My code is a simplified version of integer_lit (from rustc_ast/src/util/literal.rs) which parses both the number, its base and its suffix (which we already have) and returns a LitKind, which is also unnecessary here since we already know the end type.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 4, 2026
@GuillaumeGomez GuillaumeGomez force-pushed the number_value_proc-macro_API branch from c755b56 to ebb3161 Compare April 10, 2026 14:36
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 10, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@GuillaumeGomez
Copy link
Copy Markdown
Member Author

Added the method for f16, renamed the function only_digits into strip_underscores and improve the code of parse_number a bit to remove allocations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants