From 138aa9950309a3926c195b9be44278cb7f22f510 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 24 May 2022 22:58:28 +0400 Subject: [PATCH 1/2] Stabilize checked slice->str conversion functions --- library/core/src/str/converts.rs | 4 ++-- library/core/src/str/error.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/core/src/str/converts.rs b/library/core/src/str/converts.rs index 81b1db4ac6fed..f1055a34b9e87 100644 --- a/library/core/src/str/converts.rs +++ b/library/core/src/str/converts.rs @@ -82,9 +82,9 @@ use super::Utf8Error; /// assert_eq!("💖", sparkle_heart); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_str_from_utf8", issue = "91006")] +#[rustc_const_stable(feature = "const_str_from_utf8_shared", since = "1.63.0")] pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> { - // This should use `?` again, once it's `const` + // FIXME: This should use `?` again, once it's `const` match run_utf8_validation(v) { Ok(_) => { // SAFETY: validation succeeded. diff --git a/library/core/src/str/error.rs b/library/core/src/str/error.rs index a127dd57eee0e..4e569fcc866b6 100644 --- a/library/core/src/str/error.rs +++ b/library/core/src/str/error.rs @@ -72,7 +72,7 @@ impl Utf8Error { /// assert_eq!(1, error.valid_up_to()); /// ``` #[stable(feature = "utf8_error", since = "1.5.0")] - #[rustc_const_unstable(feature = "const_str_from_utf8", issue = "91006")] + #[rustc_const_stable(feature = "const_str_from_utf8_shared", since = "1.63.0")] #[must_use] #[inline] pub const fn valid_up_to(&self) -> usize { @@ -95,11 +95,11 @@ impl Utf8Error { /// /// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html #[stable(feature = "utf8_error_error_len", since = "1.20.0")] - #[rustc_const_unstable(feature = "const_str_from_utf8", issue = "91006")] + #[rustc_const_stable(feature = "const_str_from_utf8_shared", since = "1.63.0")] #[must_use] #[inline] pub const fn error_len(&self) -> Option { - // This should become `map` again, once it's `const` + // FIXME: This should become `map` again, once it's `const` match self.error_len { Some(len) => Some(len as usize), None => None, From 89295352ee00a5555141db5fb7bcc41c822d4aec Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 26 May 2022 13:00:14 +0400 Subject: [PATCH 2/2] Allow some internal instability --- library/core/src/str/converts.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/str/converts.rs b/library/core/src/str/converts.rs index f1055a34b9e87..b0c55ca4f5139 100644 --- a/library/core/src/str/converts.rs +++ b/library/core/src/str/converts.rs @@ -83,6 +83,7 @@ use super::Utf8Error; /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_str_from_utf8_shared", since = "1.63.0")] +#[rustc_allow_const_fn_unstable(str_internals)] pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> { // FIXME: This should use `?` again, once it's `const` match run_utf8_validation(v) {