Skip to content

Commit 5fb8a39

Browse files
committedJun 19, 2022
Auto merge of rust-lang#97367 - WaffleLapkin:stabilize_checked_slice_to_str_conv, r=dtolnay
Stabilize checked slice->str conversion functions This PR stabilizes the following APIs as `const` functions in Rust 1.63: ```rust // core::str pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error>; impl Utf8Error { pub const fn valid_up_to(&self) -> usize; pub const fn error_len(&self) -> Option<usize>; } ``` Note that the `from_utf8_mut` function is not stabilized as unique references (`&mut _`) are [unstable in const context]. FCP: rust-lang#91006 (comment) [unstable in const context]: rust-lang#57349
2 parents 6c9be6e + 8929535 commit 5fb8a39

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed
 

‎library/core/src/str/converts.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ use super::Utf8Error;
8282
/// assert_eq!("💖", sparkle_heart);
8383
/// ```
8484
#[stable(feature = "rust1", since = "1.0.0")]
85-
#[rustc_const_unstable(feature = "const_str_from_utf8", issue = "91006")]
85+
#[rustc_const_stable(feature = "const_str_from_utf8_shared", since = "1.63.0")]
86+
#[rustc_allow_const_fn_unstable(str_internals)]
8687
pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
87-
// This should use `?` again, once it's `const`
88+
// FIXME: This should use `?` again, once it's `const`
8889
match run_utf8_validation(v) {
8990
Ok(_) => {
9091
// SAFETY: validation succeeded.

‎library/core/src/str/error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Utf8Error {
7272
/// assert_eq!(1, error.valid_up_to());
7373
/// ```
7474
#[stable(feature = "utf8_error", since = "1.5.0")]
75-
#[rustc_const_unstable(feature = "const_str_from_utf8", issue = "91006")]
75+
#[rustc_const_stable(feature = "const_str_from_utf8_shared", since = "1.63.0")]
7676
#[must_use]
7777
#[inline]
7878
pub const fn valid_up_to(&self) -> usize {
@@ -95,11 +95,11 @@ impl Utf8Error {
9595
///
9696
/// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html
9797
#[stable(feature = "utf8_error_error_len", since = "1.20.0")]
98-
#[rustc_const_unstable(feature = "const_str_from_utf8", issue = "91006")]
98+
#[rustc_const_stable(feature = "const_str_from_utf8_shared", since = "1.63.0")]
9999
#[must_use]
100100
#[inline]
101101
pub const fn error_len(&self) -> Option<usize> {
102-
// This should become `map` again, once it's `const`
102+
// FIXME: This should become `map` again, once it's `const`
103103
match self.error_len {
104104
Some(len) => Some(len as usize),
105105
None => None,

0 commit comments

Comments
 (0)