Skip to content
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

Stabilize const {integer}::from_str_radix i.e. const_int_from_str #124941

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Skgland
Copy link
Contributor

@Skgland Skgland commented May 9, 2024

This PR stabilizes the feature const_int_from_str.

API Change Diff:

impl {integer} {
- pub       fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
+ pub const fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
}

impl ParseIntError {
- pub       fn kind(&self) -> &IntErrorKind;
+ pub const fn kind(&self) -> &IntErrorKind;
}

This makes it easier to parse integers at compile-time, e.g.
the example from the Tracking Issue:

env!("SOMETHING").parse::<usize>().unwrap()

could now be achived with

match usize::from_str_radix(env!("SOMETHING"), 10) {
  Ok(val) => val,
  Err(err) => panic!("Invalid value for SOMETHING environment variable."),
}

rather than having to depend on a library that implements or manually implement the parsing at compile-time.


Checklist based on Libs Stabilization Guide - When there's const involved

I am treating this as a partial stabilization as it shares a tracking issue (and is rather small), so directly opening the partial stabilization PR for the subset (feature const_int_from_str) being stabilized.

  • ping Constant Evaluation WG
  • #[allow_internal_unstable] used for access to internal can_not_overflow.
    • suggestions for alternatives are welcome
    • This is limited to can_not_overflow, which is an internal const fn. And it should be Ok as that function could just be inlined to remove the internally unstable call.
  • no unsafe involved
  • usage of intrinsic::const_eval_select Tracking Issue for const_eval_select #124625 in from_str_radix_assert to change the error message between compile-time and run-time
  • rust-labg/libs-api FCP

@rustbot
Copy link
Collaborator

rustbot commented May 9, 2024

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 9, 2024
@scottmcm scottmcm added needs-fcp This change is insta-stable, so needs a completed FCP to proceed. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels May 9, 2024
@scottmcm
Copy link
Member

scottmcm commented May 9, 2024

Looks like there hasn't been an FCP for this, so I have to flip it over to
r? libs-api

@rustbot rustbot assigned BurntSushi and unassigned scottmcm May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-fcp This change is insta-stable, so needs a completed FCP to proceed. 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. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants