mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
86721a4c90
Stabilize const `{integer}::from_str_radix` i.e. `const_int_from_str` This PR stabilizes the feature `const_int_from_str`. - ACP Issue: rust-lang/libs-team#74 - Implementation PR: rust-lang/rust#99322 - Part of Tracking Issue: rust-lang/rust#59133 API Change Diff: ```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: ```rust env!("SOMETHING").parse::<usize>().unwrap() ``` could now be achived with ```rust 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](https://std-dev-guide.rust-lang.org/development/stabilization.html#when-theres-const-involved) I am treating this as a [partial stabilization](https://std-dev-guide.rust-lang.org/development/stabilization.html#partial-stabilizations) 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. - [x] ping Constant Evaluation WG - [x] no unsafe involved - [x] no `#[allow_internal_unstable]` - [ ] usage of `intrinsic::const_eval_select` rust-lang/rust#124625 in `from_str_radix_assert` to change the error message between compile-time and run-time - [ ] [rust-labg/libs-api FCP](https://github.com/rust-lang/rust/pull/124941#issuecomment-2207021921) |
||
---|---|---|
.. | ||
assembly | ||
auxiliary | ||
codegen | ||
codegen-units | ||
coverage | ||
coverage-run-rustdoc | ||
crashes | ||
debuginfo | ||
incremental | ||
mir-opt | ||
pretty | ||
run-make | ||
run-pass-valgrind | ||
rustdoc | ||
rustdoc-gui | ||
rustdoc-js | ||
rustdoc-js-std | ||
rustdoc-json | ||
rustdoc-ui | ||
ui | ||
ui-fulldeps | ||
COMPILER_TESTS.md |