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

float_values! {
// FIXME: To be uncommented when `f16` is stable.
// f16 => f16_value,
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.

Shouldn't this be available, but unstable?

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?

(output, base)
}

fn only_digits(value_s: &str) -> Cow<'_, str> {
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.

This isn't really only_digits... it's more like "not _"?

@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
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