Skip to content

Commit

Permalink
Rollup merge of #137277 - m4rch3n1ng:stabilize-inherent-str-construct…
Browse files Browse the repository at this point in the history
…ors, r=tgross35

stabilize `inherent_str_constructors`

fcp done in #131114 (comment).

tracking issue: #131114
closes: #131114
  • Loading branch information
matthiaskrgr authored Feb 19, 2025
2 parents 704a024 + b24f775 commit be73ea8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 59 deletions.
25 changes: 7 additions & 18 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ impl str {
/// Basic usage:
///
/// ```
/// #![feature(inherent_str_constructors)]
///
/// // some bytes, in a vector
/// let sparkle_heart = vec![240, 159, 146, 150];
///
Expand All @@ -213,8 +211,6 @@ impl str {
/// Incorrect bytes:
///
/// ```
/// #![feature(inherent_str_constructors)]
///
/// // some invalid bytes, in a vector
/// let sparkle_heart = vec![0, 159, 146, 150];
///
Expand All @@ -227,8 +223,6 @@ impl str {
/// A "stack allocated string":
///
/// ```
/// #![feature(inherent_str_constructors)]
///
/// // some bytes, in a stack-allocated array
/// let sparkle_heart = [240, 159, 146, 150];
///
Expand All @@ -237,7 +231,8 @@ impl str {
///
/// assert_eq!("💖", sparkle_heart);
/// ```
#[unstable(feature = "inherent_str_constructors", issue = "131114")]
#[stable(feature = "inherent_str_constructors", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "inherent_str_constructors", since = "CURRENT_RUSTC_VERSION")]
#[rustc_diagnostic_item = "str_inherent_from_utf8"]
pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
converts::from_utf8(v)
Expand All @@ -250,8 +245,6 @@ impl str {
/// Basic usage:
///
/// ```
/// #![feature(inherent_str_constructors)]
///
/// // "Hello, Rust!" as a mutable vector
/// let mut hellorust = vec![72, 101, 108, 108, 111, 44, 32, 82, 117, 115, 116, 33];
///
Expand All @@ -264,16 +257,14 @@ impl str {
/// Incorrect bytes:
///
/// ```
/// #![feature(inherent_str_constructors)]
///
/// // Some invalid bytes in a mutable vector
/// let mut invalid = vec![128, 223];
///
/// assert!(str::from_utf8_mut(&mut invalid).is_err());
/// ```
/// See the docs for [`Utf8Error`] for more details on the kinds of
/// errors that can be returned.
#[unstable(feature = "inherent_str_constructors", issue = "131114")]
#[stable(feature = "inherent_str_constructors", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_str_from_utf8", issue = "91006")]
#[rustc_diagnostic_item = "str_inherent_from_utf8_mut"]
pub const fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> {
Expand All @@ -294,8 +285,6 @@ impl str {
/// Basic usage:
///
/// ```
/// #![feature(inherent_str_constructors)]
///
/// // some bytes, in a vector
/// let sparkle_heart = vec![240, 159, 146, 150];
///
Expand All @@ -307,7 +296,8 @@ impl str {
/// ```
#[inline]
#[must_use]
#[unstable(feature = "inherent_str_constructors", issue = "131114")]
#[stable(feature = "inherent_str_constructors", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "inherent_str_constructors", since = "CURRENT_RUSTC_VERSION")]
#[rustc_diagnostic_item = "str_inherent_from_utf8_unchecked"]
pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
// SAFETY: converts::from_utf8_unchecked has the same safety requirements as this function.
Expand All @@ -324,16 +314,15 @@ impl str {
/// Basic usage:
///
/// ```
/// #![feature(inherent_str_constructors)]
///
/// let mut heart = vec![240, 159, 146, 150];
/// let heart = unsafe { str::from_utf8_unchecked_mut(&mut heart) };
///
/// assert_eq!("💖", heart);
/// ```
#[inline]
#[must_use]
#[unstable(feature = "inherent_str_constructors", issue = "131114")]
#[stable(feature = "inherent_str_constructors", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "inherent_str_constructors", since = "CURRENT_RUSTC_VERSION")]
#[rustc_diagnostic_item = "str_inherent_from_utf8_unchecked_mut"]
pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str {
// SAFETY: converts::from_utf8_unchecked_mut has the same safety requirements as this function.
Expand Down
1 change: 0 additions & 1 deletion tests/ui/lint/invalid_from_utf8.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ check-pass

#![feature(concat_bytes)]
#![feature(inherent_str_constructors)]
#![warn(invalid_from_utf8_unchecked)]
#![warn(invalid_from_utf8)]

Expand Down
Loading

0 comments on commit be73ea8

Please sign in to comment.